Two problems.
cat still buffers its output when its STDOUT is connected to a terminal. Like Perl's default, it uses block buffering when its STDOUT isn't connected to a terminal and line buffering when it is. You'll have to send a newline to get it to react.
You're program is too fast! cat never has a change to run. You need to wait for output from cat.
#!/usr/bin/perl -w use strict; use IPC::Run qw( start pump finish timeout ); my @tok_program = 'cat'; my ($TOK_IN, $TOK_OUT, $TOK_ERR); my $TOK = start \@tok_program, '<', \$TOK_IN, '1>pty>', \$TOK_OUT, '2>', \$TOK_ERR or die "Error: $?;\n"; while (my $line = <STDIN> ) { # Send input. $TOK_IN = $line; pump $TOK while length $TOK_IN; # Wait for output. pump $TOK while $TOK_OUT !~ /\n\z/; print "out: $TOK_OUT"; $TOK_OUT = ''; } finish $TOK or die "returned $?";
Expect also uses a pty, and it might be better suited to control interactive application.
In reply to Re: IPC::Run and subprocess interaction
by ikegami
in thread IPC::Run and subprocess interaction
by xhudik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |