Parallel::Jobs - run jobs in parallel with access to their stdout and stderr |
Parallel::Jobs - run jobs in parallel with access to their stdout and stderr
use Parallel::Jobs; use Parallel::Jobs qw(start_job watch_jobs);
$pid = Parallel::Jobs::start_job('cmd', ... args ...); $pid = Parallel::Jobs::start_job('cmd ... args ...'); $pid = Parallel::Jobs::start_job({ stdin_file => filename | stdin_handle => *HANDLE, stdout_handle => *HANDLE | stdout_capture => 1, stderr_handle => *HANDLE | stderr_capture => 1 }, ... cmd as above ...);
($pid, $event, $data) = Parallel::Jobs::watch_jobs();
The Parallel::Jobs module allows you to run multiple jobs in parallel with fine-grained control over their stdin, stdout and stderr.
You can specify the command to run as a single string or as a list
specifying the command and its arguments, as in the IPC::Open3 manpage. If
your version of IPC::Open3 supports '-' as the command,
Parallel::Jobs::start_job() will fork to a Perl child in a manner
analogous to open(FOO, "-|")
.
If your first argument is a reference to a hash, it can specify the parameters shown above. By default, stdin for each job is set to /dev/null and stdout and stderr are set to the stdout and stderr of the calling process.
If you specify stdin_handle, stdout_handle or stderr_handle, the handle will be copied the original handle will thus not be modified.
Each time you call Parallel::Jobs::watch_jobs(), it will return the
process ID of the job with which an event has occured, the event type,
and the data associated with that event. If there are no more jobs to
watch, watch_jobs()
will return undef.
The relevant events are as follows:
Note that it is possible to receive STDOUT or STDERR events from a process after its EXIT event, i.e., you may receive an EXIT event before you've read all of a process's output.
Jonathan Kamens <jik@kamens.brookline.ma.us>
Copyright 2002-2003 by WorldWinner.com, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Parallel::Jobs - run jobs in parallel with access to their stdout and stderr |