NAME

Parallel::Jobs - run jobs in parallel with access to their stdout and stderr

SYNOPSIS

  use Parallel::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();

DESCRIPTION

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 IPC::Open3.

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:

EXIT

The indicated process has exited. The returned data is the value of $? from the exited process. The process has already been waited for (i.e., you don't need to do any cleanup on it).

STDOUT

Output has been received on stdout. The returned data is the output that was received, or an empty string if EOF was received.

STDERR

Output has been received on stderr. The returned data is the output that was received, or an empty string if EOF was received.

If you mix some jobs for which you are capturing stdout and/or stderr with some jobs for which you are not, watch_jobs() may sometimes not notice that a job whose output isn't being captured has exited until a job whose output is being captured exits or generates output.

AUTHOR

Jonathan Kamens <jik@kamens.brookline.ma.us>

COPYRIGHT AND LICENSE

Copyright 2002 by WorldWinner.com, Inc.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.