Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2018-02-22 17:02 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (295 votes). Check out past polls.