Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://393312]
[erix]: never too late to pull legs
[LanX]: Official YAPC Africa 2013 Announcement
erix always game to pull legs from sleeping cells
[erix]: hm nice might do a spot of diving - Red Sea is said to be beautiful
[LanX]: well too many terrorist tourists
[erix]: I guess I can pass for a native
[LanX]: talking about destruction of diving spots
[LanX]: Nodes to consider
[erix]: oops - got to run, see you later
[robby_dobby]: erix: 'appy day'ving

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2017-04-24 16:17 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.