summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/IPC
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-03-10 21:56:14 +0000
committerKarl Berry <karl@freefriends.org>2019-03-10 21:56:14 +0000
commite0a2a718e89f9700d627f1e6a8eea8f21d2fbeb8 (patch)
tree39972f65008b0d70f306a5f976494d29411bc41e /Master/tlpkg/tlperl/lib/IPC
parentb206fdc77d81ed1600949062f08de5690a4bf66f (diff)
tl19 perl 5.28.1 for Windows, from Siep
git-svn-id: svn://tug.org/texlive/trunk@50322 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/IPC')
-rw-r--r--Master/tlpkg/tlperl/lib/IPC/Cmd.pm32
1 files changed, 30 insertions, 2 deletions
diff --git a/Master/tlpkg/tlperl/lib/IPC/Cmd.pm b/Master/tlpkg/tlperl/lib/IPC/Cmd.pm
index c0e25a22fb3..a42c21b84ee 100644
--- a/Master/tlpkg/tlperl/lib/IPC/Cmd.pm
+++ b/Master/tlpkg/tlperl/lib/IPC/Cmd.pm
@@ -18,7 +18,7 @@ BEGIN {
$HAVE_MONOTONIC
];
- $VERSION = '0.96';
+ $VERSION = '1.00';
$VERBOSE = 0;
$DEBUG = 0;
$WARN = 1;
@@ -242,7 +242,7 @@ sub can_run {
} else {
for my $dir (
File::Spec->path,
- File::Spec->curdir
+ ( IS_WIN32 ? File::Spec->curdir : () )
) {
next if ! $dir || ! -d $dir;
my $abs = File::Spec->catfile( IS_WIN32 ? Win32::GetShortPathName( $dir ) : $dir, $command);
@@ -531,6 +531,7 @@ sub open3_run {
$child_err->autoflush(1);
my $pid = open3($child_in, $child_out, $child_err, $cmd);
+ Time::HiRes::usleep(1);
# push my child's pid to our parent
# so in case i am killed parent
@@ -742,6 +743,29 @@ STDOUT from the executing program.
Coderef of a subroutine to call when a portion of data is received on
STDERR from the executing program.
+=item C<wait_loop_callback>
+
+Coderef of a subroutine to call inside of the main waiting loop
+(while C<run_forked> waits for the external to finish or fail).
+It is useful to stop running external process before it ends
+by itself, e.g.
+
+ my $r = run_forked("some external command", {
+ 'wait_loop_callback' => sub {
+ if (condition) {
+ kill(1, $$);
+ }
+ },
+ 'terminate_on_signal' => 'HUP',
+ });
+
+Combined with C<stdout_handler> and C<stderr_handler> allows terminating
+external command based on its output. Could also be used as a timer
+without engaging with L<alarm> (signals).
+
+Remember that this code could be called every millisecond (depending
+on the output which external command generates), so try to make it
+as lightweight as possible.
=item C<discard_output>
@@ -1075,6 +1099,10 @@ sub run_forked {
push @{$ready_fds}, $select->can_read(1/100) if $child_finished;
}
+ if ($opts->{'wait_loop_callback'} && ref($opts->{'wait_loop_callback'}) eq 'CODE') {
+ $opts->{'wait_loop_callback'}->();
+ }
+
Time::HiRes::usleep(1);
}