Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2015-10-09 05:50 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (233 votes), past polls