pipe method
Similar to the | on linux it allows to pipe the stdout
of the ran commands as stdin to the next command.
Implementation
Future<List<ProcessResult>> pipe(String script) async {
var results = await this;
if (results is ProcessResultInternalList) {
var shellResults = results.shellProcessResults;
var output = shellResults.stdoutAsUint8List;
var shell = shellResults.shell;
var stdinController = ShellUint8ListController();
stdinController.sink.add(output);
var newShell = shell.cloneWithOptions(
shell.options.clone(stdin: stdinController.stream),
);
newShell = shell.cloneWithOptions(shell.options.clone());
try {
var newResults = await newShell.run(script);
return newResults;
} finally {
stdinController.close();
}
}
throw UnsupportedError(
'Invalid results type: ${results.runtimeType}, expected ProcessResultInternalList',
);
}