Running vi from Perl

D

DrStrangepork

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?
 
W

Walter Roberson

: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?
 
S

Simon Taylor

DrStrangepork said:
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
 
T

Tad McClellan

DrStrangepork said:
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?
 
D

DrStrangepork

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.
 
D

DrStrangepork

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!
 
W

Walter Roberson

: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).
 
G

Gerhard M

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
 
J

Joe Smith

Gerhard said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top