Re: Bi-directional communication with another process

2017-07-27 Thread David Warring
Thanks Timo, A Proc::Async example, after reading the doco. Agree, that't better, even for the simple case :-) - David my $proc = Proc::Async.new('sh', '-c', 'for x in `seq 1 1` ; do echo "o$x"; echo "e$x" 1>&2; done'); # subscribe to new output from out and err handles: $proc.stdout.tap(-> $

Re: Bi-directional communication with another process

2017-07-27 Thread Brandon Allbery
select() in this context is arguably a workaround for lack of threads, although it can also be used to simulate threading ("green threads"). On Thu, Jul 27, 2017 at 8:41 PM, David Warring wrote: > Perl 5 and C have the select call that lets you determine which of a group > of file-descriptor are

Re: Bi-directional communication with another process

2017-07-27 Thread Timo Paulssen
We have Proc::Async which removes the need for the select call itself

Re: Bi-directional communication with another process

2017-07-27 Thread David Warring
Perl 5 and C have the select call that lets you determine which of a group of file-descriptor are ready for reading and writing. I thought it might be useful here. https://en.wikipedia.org/wiki/Select_(Unix) I've found a module by Tadzik, https://github.com/tadzik/IO-Select, but it's looking defu

Re: Bi-directional communication with another process

2017-07-27 Thread Brandon Allbery
On Thu, Jul 27, 2017 at 7:49 PM, Norman Gaywood wrote: > my $input = q:to/EOS/; > line of text > another line > EOS > > my $cat = run 'cat', '-n', :in($input.print), :out; > my $output = $cat.out.get; > $cat.in.close; > $cat.out.close; > > say "done"; > say $output; > > But that is not correct.

Re: Bi-directional communication with another process

2017-07-27 Thread Timo Paulssen
You'll want to just pass :in and then use "$cat.in.print($input); $cat.in.close;" We just had a thread about this on reddit with zoffix and me weighing in: https://www.reddit.com/r/perl/comments/6pwqcy/how_do_i_interact_with_a_shell_program_using_perl/ On 07/28/2017 01:49 AM, Norman Gaywood

Bi-directional communication with another process

2017-07-27 Thread Norman Gaywood
>From inside a program I'd like to send some input to the stdin of external program and read back the stdout. The example in https://docs.perl6.org/language/ipc under proc comes close to what I want: my $echo = run 'echo', 'Hello, world', :out; my $cat = run 'cat', '-n', :in($echo.out), :out; sa