bloonix has asked for the wisdom of the Perl Monks concerning the following question:
Now my question to you is: could it be simplier? I don't know if my code example is too much dirty, because I haven't the finest idea of windows.#!perl.exe use strict; use warnings; use threads; use threads::shared; use Data::Dumper; use IPC::Open3; use Symbol; my %data : shared; my $timeout = 3; my $command = "perl test.pl"; my $tid = threads->create(sub { execute($command) }); while (--$timeout) { if ($tid->is_joinable) { $tid->join; last; } sleep 1; } if ($timeout == 0) { if ($data{pid}) { kill -9, $data{pid}; } $tid->detach; $data{timedout} = 1; } print Dumper(\%data); sub execute { my $in = Symbol::gensym(); my $out = Symbol::gensym(); my $err = Symbol::gensym(); my $pid = open3($in, $out, $err, @_); close $in; $data{pid} = $pid; # sorry for that dirty handling of $out and $err :-) # it was just a hack for tests $data{stdout} = do { local $/; <$out> }; $data{stderr} = do { local $/; <$err> }; close $out; close $err; threads->exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Windows, threads and IPC::Open3
by BrowserUk (Patriarch) on Nov 07, 2010 at 22:18 UTC | |
|
Re: Windows, threads and IPC::Open3
by ikegami (Patriarch) on Nov 07, 2010 at 21:01 UTC | |
by bloonix (Monk) on Nov 07, 2010 at 22:53 UTC | |
by ikegami (Patriarch) on Nov 08, 2010 at 01:56 UTC | |
by ikegami (Patriarch) on Nov 08, 2010 at 01:57 UTC |