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
=====
# 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.

print "Hello World!\n";
print "Enter something: ";
chomp ($foo = <STDIN>);
print "Thanks for inputting that $foo\n";


wraptest.pl
========

$| = 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";

output
=====

in wraptest
<PROMPT>
hi Hello World!
hi Enter something: Thanks for inputting that $PROMPT
exit value: 0

I’d like to modify wraptest.pl so that the output would be

in wraptest
hi Hello World!
hi Enter something: <PROMPT>
hi Thanks for inputting that $PROMPT
exit value: 0

Thanks


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to