in reply to IPC::Run and subprocess interaction
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: IPC::Run and subprocess interaction
by xhudik (Initiate) on Jul 15, 2011 at 07:52 UTC | |
by ikegami (Patriarch) on Jul 15, 2011 at 18:16 UTC | |
by xhudik (Initiate) on Jul 18, 2011 at 15:24 UTC | |
by ikegami (Patriarch) on Jul 18, 2011 at 17:27 UTC |