Running vi from Perl

Discussion in 'Perl Misc' started by DrStrangepork, Oct 6, 2004.

  1. I wrote a script from which I sometimes launch a system command. In
    Win32, this system call launches Notepad, but in Linux it must launch
    vi. It does, but I get a warning "Vim: Warning: Output is not to a
    terminal". vi is there, because the commands work (like :q exits and
    I am returned to my perl script), but like the warning says, no
    output. How can I resolve this problem?
    DrStrangepork, Oct 6, 2004
    #1
    1. Advertising

  2. In article <>,
    DrStrangepork <> wrote:
    :I wrote a script from which I sometimes launch a system command. In
    :Win32, this system call launches Notepad, but in Linux it must launch
    :vi. It does, but I get a warning "Vim: Warning: Output is not to a
    :terminal".

    What's your stdin and stdout for the 'vi' command that you are
    system()'ing ? Are you taking care to redirect the I/O in the
    command line that you are sending to system() ? Are you using
    a dup/fork/dup/system setup to get the stdin of your perl script
    to be the stdin of the system() command? Are you redirecting
    < /dev/tty > /dev/tty ? Are you stat'ing your perl stdin
    to find out whether it is a character device, running through /dev
    to find the matching device name for that major/minor combination,
    and redirecting from/to that in your system() ? How do you want
    your program to gracefully happen the cases where there is no
    terminal available (e.g., batch job, or you've managed to become
    detached from a controlling terminal), or where your perl
    script has stdin or stdout redirected to/from a pipe or file?
    --
    I wrote a hack in microcode,
    with a goto on each line,
    it runs as fast as Superman,
    but not quite every time! -- Don Libes et al.
    Walter Roberson, Oct 6, 2004
    #2
    1. Advertising

  3. DrStrangepork

    Simon Taylor Guest

    DrStrangepork wrote:
    > I wrote a script from which I sometimes launch a system command. In
    > Win32, this system call launches Notepad, but in Linux it must launch
    > vi. It does, but I get a warning "Vim: Warning: Output is not to a
    > terminal". vi is there, because the commands work (like :q exits and
    > I am returned to my perl script), but like the warning says, no
    > output. How can I resolve this problem?


    It sounds like the output of vim is being redirected into a pipe.

    Your problem would be a lot easier for people here to comment on if you
    posted a small code sample, that clearly demonstrates the problem

    Hope to hear from you soon.

    Regards,

    Simon Taylor
    Simon Taylor, Oct 7, 2004
    #3
  4. DrStrangepork <> wrote:
    > I wrote a script from which I sometimes launch a system command. In
    > Win32, this system call launches Notepad, but in Linux it must launch
    > vi. It does, but I get a warning "Vim: Warning: Output is not to a
    > terminal". vi is there, because the commands work (like :q exits and
    > I am returned to my perl script), but like the warning says, no
    > output. How can I resolve this problem?



    By changing your code.

    (If you want to know how your code needs to be changed, you will
    need to show us the code in question, we are not mind readers.
    )


    Have you seen the Posting Guidelines that are posted here frequently?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Oct 7, 2004
    #4
  5. I did not post my code, because I thought it was a simple answer, and
    because my code won't help, but I'll give it anyway:

    `p4 protect`; or system "p4 protect";

    Both versions have the same problem. In Win32, it launches Notepad.
    In Linux, it launches vi and I get the warning I noted.
    DrStrangepork, Oct 7, 2004
    #5
  6. (DrStrangepork) wrote in message news:<>...
    > I wrote a script from which I sometimes launch a system command. In
    > Win32, this system call launches Notepad, but in Linux it must launch
    > vi. It does, but I get a warning "Vim: Warning: Output is not to a
    > terminal". vi is there, because the commands work (like :q exits and
    > I am returned to my perl script), but like the warning says, no
    > output. How can I resolve this problem?


    I figured it out. The proper code is

    system "p4 protect";

    Thanks!
    DrStrangepork, Oct 7, 2004
    #6
  7. In article <>,
    DrStrangepork <> wrote:
    :I did not post my code, because I thought it was a simple answer, and
    :because my code won't help, but I'll give it anyway:

    :`p4 protect`; or system "p4 protect";

    :Both versions have the same problem. In Win32, it launches Notepad.
    :In Linux, it launches vi and I get the warning I noted.

    Then your problem is in assuming that stdin and stdout are connected
    to your terminal (or that there is a controlling terminal at all.)

    I would suggest that at the very least, you change the linux 'p4'
    script to be closer to

    #!/bin/sh
    [ $# -eq 0 ] && echo "Syntax: $0 filename" >&2 && exit 1
    /usr/bin/vi "$@" 1>&0 2>&1

    That is, send the stdout (file descriptor #1) to the location of stdin
    (file descriptor #0), and send stderr (file descriptor #2) to the same
    place as stdout (file descriptor #1).
    --
    Inevitably, someone will flame me about this .signature.
    Walter Roberson, Oct 7, 2004
    #7
  8. DrStrangepork

    Gerhard M Guest

    (DrStrangepork) wrote in message news:<>...
    > (DrStrangepork) wrote in message news:<>...
    > > I wrote a script from which I sometimes launch a system command. In
    > > Win32, this system call launches Notepad, but in Linux it must launch
    > > vi. It does, but I get a warning "Vim: Warning: Output is not to a
    > > terminal". vi is there, because the commands work (like :q exits and
    > > I am returned to my perl script), but like the warning says, no
    > > output. How can I resolve this problem?

    >
    > I figured it out. The proper code is
    >
    > system "p4 protect";
    >
    > Thanks!


    i don't now "p4" and "which p4" will return "no p4 in ....".
    I've tried

    perl <<!
    system ("vi test.txt");
    print "DONE\n";
    !

    on various systems without any problems:
    uname -srv
    1) HP-UX B.11.23 U
    2) OSF1 V5.1 1885
    3) Linux 2.4.20-4GB #1 Mon Apr 26 16:44:14 UTC 2004

    what is your p4, which platform is used, and provide some more code
    (code of "p4" and code of your script)
    if your p4 is a script, using "vi $@ &", the message is OK cause vi
    (vim) needs to be connected to STDIN.

    gerhard
    Gerhard M, Oct 8, 2004
    #8
  9. DrStrangepork

    Joe Smith Guest

    Gerhard M wrote:

    > (DrStrangepork) wrote in message news:<>...
    >
    >> (DrStrangepork) wrote in message news:<>...
    >>
    >>>I wrote a script from which I sometimes launch a system command. In
    >>>Win32, this system call launches Notepad, but in Linux it must launch
    >>>vi. It does, but I get a warning "Vim: Warning: Output is not to a
    >>>terminal". vi is there, because the commands work (like :q exits and
    >>>I am returned to my perl script), but like the warning says, no
    >>>output. How can I resolve this problem?

    >>
    >>I figured it out. The proper code is
    >>
    >> system "p4 protect";
    >>
    >>Thanks!

    >
    >
    > i don't now "p4" and "which p4" will return "no p4 in ....".


    I know that 'p4' is a client for the Perforce application, but
    that is irrelevant. The key is that
    $_ = `command_that_calls_vi $filename`;
    cannot be expected to work, and indeed it does not.

    As rickKasten discovered,
    system "command_that_calls_vi $filename";
    does work.

    -Joe
    Joe Smith, Oct 8, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,767
  2. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    286
    PerlFAQ Server
    Jan 23, 2011
  3. PerlFAQ Server
    Replies:
    0
    Views:
    652
    PerlFAQ Server
    Feb 3, 2011
  4. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    276
    PerlFAQ Server
    Feb 27, 2011
  5. Replies:
    4
    Views:
    285
    ccc31807
    Jul 29, 2011
Loading...

Share This Page