Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How do you properly tty-ify a non-tty STDOUT?

by ph713 (Pilgrim)
on Sep 23, 2004 at 20:22 UTC ( #393312=note: print w/ replies, xml ) Need Help??


in reply to How do you properly tty-ify a non-tty STDOUT?

Just for the record, here's the final code from the actual script it's being used in, which works correctly. This subroutine forks off an external command and returns a filehandle that you can read and write to, and convinces the external program that it's running in a terminal.

use IO::Handle; use IO::Pty; use POSIX; sub forkptycmd($) { my $cmd = shift; my $pty = new IO::Pty; my $pid = fork; if(!defined($pid)) { die "error forking: $!"; } if($pid==0) { POSIX::setsid(); my $slave = $pty->slave; close($pty); STDOUT->fdopen($slave,'>') || die $!; STDIN->fdopen($slave,'<') || die $!; STDERR->fdopen(\*STDOUT,'>') || die $!; close($slave); exec($cmd); } $pty->close_slave(); return $pty; }


Comment on Re: How do you properly tty-ify a non-tty STDOUT?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://393312]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-08-28 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (256 votes), past polls