Loading ...
Sorry, an error occurred while loading the content.

32287Output/Input is not to/from a terminal

Expand Messages
  • Walter Briscoe
    Apr 30, 2003
      With a vim built with Make_ivc.mak on w2ksp3, I locked up a terminal
      session with the following contrived example:
      C:\wfb\vim\bld> echo hello | vim > t.t
      Vim: Warning: Output is not to a terminal
      Vim: Warning: Input is not from a terminal

      Neither message is documented.

      :help todo contains
      7 Allow using Vim in a pipe: "ls | vim -u xxx.vim - | yyy". Only needs
      implementing ":w" to stdout in the buffer that was read from stdin.

      I did a quick and dirty proof of concept on this. It worked once in
      w2ksp3 with a vimd built with Make_ivc.mak. It does not work with gvimd
      because stdout is unsupported by windoze programs.
      The command which worked was
      C:\wfb\vim\bld\vim62a\src> echo hello| vimd "+set ff=unix" +x - > t.x
      Vim: Warning: Output is not to a terminal

      C:\wfb\vim\bld\vim62a\src> dumpfile t.x
      00000000: 68 65 6C 6C 6F 0A - hello.

      It is quite right. 0D 0A is transformed to 0D 0D 0A as shown below when
      ff=dos
      C:\wfb\vim\bld\vim62a\src> echo hello| vimd "+set ff=dos" +x - > t.x
      Vim: Warning: Output is not to a terminal

      C:\wfb\vim\bld\vim62a\src> dumpfile t.x
      00000000: 68 65 6C 6C 6F 0D 0D 0A - hello...


      *** src/0ex_cmds.c Sat Apr 19 14:05:56 2003
      --- src/ex_cmds.c Wed Apr 30 12:29:58 2003
      ***************
      *** 2055,2060 ****
      --- 2055,2061 ----
      do_write(eap)
      exarg_T *eap;
      {
      + extern int stdout_isatty; /* is stdout a terminal? - hack to allow w to stdout */
      int other;
      char_u *fname = NULL; /* init to shut up gcc */
      char_u *ffname;
      ***************
      *** 2129,2135 ****
      #ifdef FEAT_QUICKFIX
      bt_dontwrite_msg(curbuf) ||
      #endif
      ! check_fname() == FAIL || check_readonly(&eap->forceit, curbuf)))
      goto theend;

      if (!other)
      --- 2130,2136 ----
      #ifdef FEAT_QUICKFIX
      bt_dontwrite_msg(curbuf) ||
      #endif
      ! (stdout_isatty && check_fname() == FAIL) || check_readonly(&eap->forceit, curbuf)))
      goto theend;

      if (!other)
      *** src/0fileio.c Mon Apr 21 16:08:54 2003
      --- src/fileio.c Wed Apr 30 13:50:38 2003
      ***************
      *** 2403,2411 ****
      vim_acl_T acl = NULL; /* ACL copied from original file to
      backup or new file */
      #endif
      !
      ! if (fname == NULL || *fname == NUL) /* safety check */
      ! return FAIL;

      /*
      * Disallow writing from .exrc and .vimrc in current directory for
      --- 2403,2409 ----
      vim_acl_T acl = NULL; /* ACL copied from original file to
      backup or new file */
      #endif
      ! extern int stdout_isatty; /* is stdout a terminal? - hack to allow w to stdout */

      /*
      * Disallow writing from .exrc and .vimrc in current directory for
      ***************
      *** 2414,2424 ****
      if (check_secure())
      return FAIL;

      ! /* Avoid a crash for a long name. */
      ! if (STRLEN(fname) >= MAXPATHL)
      {
      ! EMSG(_(e_longname));
      ! return FAIL;
      }

      #ifdef FEAT_MBYTE
      --- 2412,2428 ----
      if (check_secure())
      return FAIL;

      ! if (stdout_isatty)
      {
      ! if (fname == NULL || *fname == NUL) /* safety check */
      ! return FAIL;
      !
      ! /* Avoid a crash for a long name. */
      ! if (STRLEN(fname) >= MAXPATHL)
      ! {
      ! EMSG(_(e_longname));
      ! return FAIL;
      ! }
      }

      #ifdef FEAT_MBYTE
      ***************
      *** 3391,3396 ****
      --- 3395,3410 ----
      * (this may happen when the user reached his quotum for number of files).
      * Appending will fail if the file does not exist and forceit is FALSE.
      */
      + if (!stdout_isatty)
      + {
      + fd = 1;
      + #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
      + /* Force binary I/O on stdout to avoid CR-LF -> LF conversion. */
      + if (get_fileformat(curbuf) == EOL_UNIX)
      + setmode(1, O_BINARY);
      + #endif
      + }
      + else
      while ((fd = mch_open((char *)wfname, O_WRONLY | O_EXTRA | (append
      ? (forceit ? (O_APPEND | O_CREAT) : O_APPEND)
      : (O_CREAT | O_TRUNC))
      *** src/0main.c Mon Apr 28 09:11:58 2003
      --- src/main.c Wed Apr 30 14:04:28 2003
      ***************
      *** 29,34 ****
      --- 29,36 ----
      # include <limits.h>
      #endif

      + int stdout_isatty; /* is stdout a terminal? - hack to allow w to stdout */
      +
      #if defined(UNIX) || defined(VMS)
      static int file_owned __ARGS((char *fname));
      #endif
      ***************
      *** 141,147 ****
      int diff_mode = FALSE; /* start with 'diff' set */
      #endif
      int evim_mode = FALSE; /* started as "evim" */
      - int stdout_isatty; /* is stdout a terminal? */
      int input_isatty; /* is active input a terminal? */
      #ifdef MSWIN
      int full_path = FALSE;
      --- 143,148 ----

      --
      Walter Briscoe
    • Show all 6 messages in this topic