Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Running vi from Perl

Reply
Thread Tools

Running vi from Perl

 
 
DrStrangepork
Guest
Posts: n/a
 
      10-06-2004
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?
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      10-06-2004
In article <(E-Mail Removed) >,
DrStrangepork <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Simon Taylor
Guest
Posts: n/a
 
      10-06-2004
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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-06-2004
DrStrangepork <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
DrStrangepork
Guest
Posts: n/a
 
      10-07-2004
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.
 
Reply With Quote
 
DrStrangepork
Guest
Posts: n/a
 
      10-07-2004
(E-Mail Removed) (DrStrangepork) wrote in message news:<(E-Mail Removed). com>...
> 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!
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      10-07-2004
In article <(E-Mail Removed) >,
DrStrangepork <(E-Mail Removed)> 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.
 
Reply With Quote
 
Gerhard M
Guest
Posts: n/a
 
      10-08-2004
(E-Mail Removed) (DrStrangepork) wrote in message news:<(E-Mail Removed) om>...
> (E-Mail Removed) (DrStrangepork) wrote in message news:<(E-Mail Removed). com>...
> > 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
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      10-08-2004
Gerhard M wrote:

> (E-Mail Removed) (DrStrangepork) wrote in message news:<(E-Mail Removed) om>...
>
>>(E-Mail Removed) (DrStrangepork) wrote in message news:<(E-Mail Removed). com>...
>>
>>>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble running Perl script from within a Perl script laredotornado@zipmail.com Perl Misc 4 07-29-2011 01:44 PM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 02-27-2011 11:00 PM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 02-03-2011 11:00 AM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments