process_runner 2.0.0
process_runner: ^2.0.0 copied to clipboard
A process invocation astraction for Dart that manages a multiprocess queue.
Process #
A process runner for Dart that uses the ProcessManager
class from package:process
, and manages the stderr and stdout properly so that you don't lose any output.
Like dart:io
and package:process
, it supplies a rich, Dart-idiomatic API for
spawning OS processes, with the added benefit of easy retrieval of stdout and stderr from the result of running the process, with proper waiting for the process and stderr/stdout streams to be closed.
In addition to being able to launch processes separately, it allows creation of a pool of worker processes, and manages running them with a set number of active processes, and manages collection of their stdout, stderr, and interleaved stdout and stderr.
See the example for more information on how to use it, but the basic usage for ProcessRunner
is:
ProcessRunnerResult result = await processRunner.runProcess(['command', 'arg1', 'arg2']);
// Print stdout:
print(result.stdout);
// Print stderr:
print(result.stderr);
// Print interleaved stdout/stderr:
print(result.output);
For the ProcessPool
, also see the example, but it basically looks like this:
ProcessPool pool = ProcessPool(numWorkers: 2);
final List<WorkerJob> jobs = <WorkerJob>[
WorkerJob('Job 1', ['command1', 'arg1', 'arg2']),
WorkerJob('Job 2', ['command2', 'arg1']),
];
await for (final WorkerJob job in pool.startWorkers(jobs)) {
print('\nFinished job ${job.name}');
}