Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

IPC::Run and /dev/tty

by former33t (Scribe)
on Oct 31, 2006 at 15:22 UTC ( [id://581512]=perlquestion: print w/replies, xml ) Need Help??

former33t has asked for the wisdom of the Perl Monks concerning the following question:

This is a follow up to another post where I was trying to capture output from a linux shell command that sends output to both STDOUT and /dev/tty. I am able to trap the output to STDOUT, but output written directly to /dev/tty is proving more of a challenge. The code starts out like:
my @test = qw( fake -b -v 5); use IPC::Run qw(run);
Then varies between one of the two following lines:
run \@tester, \$in, \$out; run \@tester, '>pty>', \$in, '>pty>', \$out;
The first option does trap STDOUT in $out, but messages written to /dev/tty are sent to the terminal running perl script. The second option also traps STDOUT in $out and my /dev/tty output is not sent to the terminal running the script. It also doesn't show up in $out. Any idea where it is going to and how to retrieve it? Thanks in advance perl monks.

Replies are listed 'Best First'.
Re: IPC::Run and /dev/tty
by idsfa (Vicar) on Oct 31, 2006 at 15:55 UTC

    More on point of your earlier post, here's what is going on. Some programs (misguidedly, IMHO) attempt to enforce what their author considers "security" by reading or writing only to the controlling terminal. The idea being that it will somehow prevent input and output from being redirected (or intercepted), and that this is desirable. It doesn't and it isn't.

    To get around this, you need to change the controlling terminal from an existing device to your in/out/err filehandles. IO::Pty has a nice little method called make_slave_controlling_terminal(), which will take care of the necessary setsid() and filehandle hokey-pokey. To be completely lazy, you might want to look at the try script that comes with it (and basically does exactly what you want -- runs another program and logs the output).


    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
      The 'try' program you linked to worked well. Thanks for your help.
Re: IPC::Run and /dev/tty
by themage (Friar) on Oct 31, 2006 at 15:47 UTC
    Hi former33t,

    I think your code have a small error in the pseudotty definition for input (it should be '<pty<', not '>pty>'), so I wuold say that the terminal output you expected in $out is going to $in.

    It's just a guess. The second guess would be that you program is looking in its first atempt to read from a output pseudo tty.

    Try correcting this, and see if you run still don't send the tty output to $out.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://581512]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found