Basicaly, it should execute cat program and then post each input to the "cat" and wait for the answer. However, the output is not what it was supposed to be :). (The output can differs from time ti time - sometimes is completely empty, sometimes just 1 entry is empty,...) Obviously, I'm missing something but no idea what Any help will be appreciate!#!/usr/bin/perl -w use IPC::Run qw(start pump finish timeout); my $tok_program = "/bin/./cat"; my ($TOK_IN, $TOK_OUT, $TOK_ERR); my $TOK = start [$tok_program], '<pty<', \$TOK_IN,'>pty>',\$TOK_OUT, ' +2>', \$TOK_ERR , debug => 3 or die "Error: $?;\n"; while (my $line = <STDIN> ) { chomp($line); $TOK_IN = $line; $TOK_OUT = ''; $TOK_ERR = ''; print "Input2pump:$TOK_IN\n"; pump $TOK while length $TOK_IN; print "out:$TOK_OUT\n"; }
Here, the output is written but the expected output is:IPC::Run 0000 0123---7---- [#1(20574)]: debugging fd is 3 IPC::Run 0000 0123---7---- [#1(20574)]: ** starting IPC::Run 0000 0123---7---- [#1(20574)]: opening pty '0' IPC::Run 0000 012345-7---- [#1(20574)]: pty() = ( 4, 5 ) IPC::Run 0000 012345-7---- [#1(20574)]: '/bin/./cat' is absolute IPC::Run 0000 012345-7---- [#1(20574)]: kid to read 0 from pty '0' IPC::Run 0000 012345-7---- [#1(20574)]: kid 1 to read 0 from SCALAR vi +a pty '0' IPC::Run 0000 012345-7---- [#1(20574)]: kid 1 to write 1 to SCALAR via + pty '0' IPC::Run 0000 012345-7---- [#1(20574)]: kid 1 to write 2 to SCALAR IPC::Run 0000 012345678--- [#1(20574)]: pipe() = ( 6, 8 ) IPC::Run 0000 012345678--- [#1(20574)]: kid 1[]'s 0 is my 4 IPC::Run 0000 012345678--- [#1(20574)]: kid 1[]'s 1 is my 4 IPC::Run 0000 012345678--- [#1(20574)]: kid 1[]'s 2 is my 6 IPC::Run 0000 012345678--- [#1(20574)]: child: `'/bin/./cat'` IPC::Run 0000 012345678--- [#1(20574)]: opening sync pipe IPC::Run 0000 01234567890- [#1(20574)]: pipe() = ( 9, 10 ) IPC::Run 0000 01234567890- [#1(20574)]: fork() = 20575 IPC::Run 0000 0123456789-- [#1(20574)]: close( 10 ) = 0 IPC::Run 0000 01234567890- [#1(20575) cat]: Cleaning up parent's ptty +'0' IPC::Run 0000 0123-567890- [#1(20575) cat]: closing stdin, out, err IPC::Run 0000 ---3-567890- [#1(20575) cat]: open fds: 6 8 4 9 10 5 IPC::Run 0000 ---3-5-7890- [#1(20575) cat]: close( 6 ) = 0 IPC::Run 0000 ---3-5-78-0- [#1(20575) cat]: close( 9 ) = 0 IPC::Run 0000 0--3-5-78-0- [#1(20575) cat]: dup2( 5, 0 ) = 0 IPC::Run 0000 01-3-5-78-0- [#1(20575) cat]: dup2( 5, 1 ) = 1 IPC::Run 0000 0123-5-78-0- [#1(20575) cat]: dup2( 1, 2 ) = 2 IPC::Run 0000 0123-5-78-0- [#1(20575) cat]: dup2( 8, 2 ) = 2 IPC::Run 0000 0123---78-0- [#1(20575) cat]: close( 5 ) = 0 IPC::Run 0000 0123---7--0- [#1(20575) cat]: close( 8 ) = 0 IPC::Run 0000 0123---7--0- [#1(20575) cat]: execing /bin/./cat IPC::Run 0000 0123---7--0- [#1(20575) cat]: exec()ing '/bin/./cat' IPC::Run 0000 0123456789-- [#1(20574)]: read( 9 ) = 0 but true chars ' +' IPC::Run 0000 012345678--- [#1(20574)]: close( 9 ) = 0 IPC::Run 0000 01234-67---- [#1(20574)]: close( 8 ) = 0 Input2pump:1. line IPC::Run 0000 01234-67---- [#1(20574)]: ** pumping IPC::Run 0000 01234-67---- [#1(20574)]: fds for select: ----b-r----- IPC::Run 0000 01234-67---- [#1(20574)]: timeout=forever IPC::Run 0000 01234-67---- [#1(20574)]: selected ----w------- IPC::Run 0000 01234-67---- [#1(20574)]: filtering data to fd 4 (kid's +stdin) IPC::Run 0000 01234-67---- [#1(20574)]: writing to fd 4 (kid's stdin) IPC::Run 0000 01234-67---- [#1(20574)]: write( 4, '1. line' ) = 7 IPC::Run 0000 01234-67---- [#1(20574)]: exiting _select(): io occured +and break_on_io set out: Input2pump:2. line IPC::Run 0000 01234-67---- [#1(20574)]: ** pumping IPC::Run 0000 01234-67---- [#1(20574)]: fds for select: ----b-r----- IPC::Run 0000 01234-67---- [#1(20574)]: timeout=forever IPC::Run 0000 01234-67---- [#1(20574)]: selected ----b------- IPC::Run 0000 01234-67---- [#1(20574)]: filtering data to fd 4 (kid's +stdin) IPC::Run 0000 01234-67---- [#1(20574)]: writing to fd 4 (kid's stdin) IPC::Run 0000 01234-67---- [#1(20574)]: write( 4, '2. line' ) = 7 IPC::Run 0000 01234-67---- [#1(20574)]: filtering data from fd 4 (kid' +s stdout) IPC::Run 0000 01234-67---- [#1(20574)]: reading from fd 4 (kid's stdou +t) IPC::Run 0000 01234-67---- [#1(20574)]: read( 4 ) = 7 chars '1. line' IPC::Run 0000 01234-67---- [#1(20574)]: exiting _select(): io occured +and break_on_io set out:1. line
Here, there is nothing in the outputInput2pump:1. line out: Input2pump:2. line out:
In reply to IPC::Run and subprocess interaction by xhudik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |