On Tue, 2008-09-09 at 14:04 -0700, doubleHelix wrote: > I am having a problem in capturing the output and exit value from a > system command that prompts the user for input. The following shows a > simplification of the problem. Im trying to get it so that all the > text before the prompt gets output before the script gets stuck at the > prompt. I’m sure it is possible, but my knowledge of ttys and file > reads and writes is failing me now. > > test.pl > =====
use strict; use warnings; > # the less I can assume about test.pl the better. > # It shouldn’t matter if the prompt is on STDOUT or STDERR, I want to > capture all of it. > $| = 1; > print "Hello World!\n"; > print "Enter something: "; print "Enter something:\n"; > chomp ($foo = <STDIN>); chomp( my $foo = <STDIN> ); > print "Thanks for inputting that $foo\n"; > > > wraptest.pl > ======== use strict; use warnings; > > $| = 1; > print "in wraptest\n"; > open CMD, "perl test.pl 2>&1 |" or die "couldnt fork: $!"; > while ( <CMD> ) { > print "hi $_"; > } > close CMD; > print "exit value: ", $?>>8, "\n"; > This isn't exactly what you asked for but close. Perl will flush STDOUT and STDERR after every "\n" if they are connected to a terminal. For more control, see `perldoc -q flush` and `perldoc IO::Handle` -- Just my 0.00000002 million dollars worth, Shawn "Where there's duct tape, there's hope." Cross Time Cafe "Perl is the duct tape of the Internet." Hassan Schroeder, Sun's first webmaster -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/