BufferedScript class

A Script wrapper that suppresses all output and stores it in a buffer until release is called, at which point it forwards the suppressed output to stdout and stderr.

Note that this can violate the usual guarantee that stdout and stderr will emit done events immediately after done completes. Instead, they'll emit done events once done completes and release has been called.

This also doesn't consider errors emitted by the underlying script unhandled by default. Those errors are still emitted as usual through done, success, and exitCode, but users can wait to listen to these futures without worrying about unhandled exceptions.

This is useful for running multiple scripts in parallel without having their stdout and stderr streams overlap. You can wrap "background" scripts in BufferedScript and only release them once they're the only script running, or only if they fail.

Inheritance
Annotations
  • @sealed

Constructors

BufferedScript.capture(FutureOr<void> callback(Stream<List<int>> stdin), {String? name, bool onSignal(ProcessSignal signal)?, bool stderrOnly = false})
Like Script.capture, but all output is silently buffered until release is called.
factory

Properties

done Future<void>
A future that completes when the script is finished.
latefinalinherited
exitCode Future<int>
The exit code indicating the status of the script's execution.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
lines Stream<String>
Returns a stream of lines this prints to stdout.
no setterinherited
name String
A human-readable name of the script.
finalinherited
output Future<String>
Returns this script's stdout, with trailing newlines removed.
no setterinherited
outputBytes Future<Uint8List>
Returns this script's stdout as bytes.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stderr Stream<List<int>>
The script's standard error stream, typically used to emit error messages and diagnostics.
no setteroverride
stdin IOSink
The standard input stream that's used to pass data into the process.
latefinalinherited
stdout Stream<List<int>>
The script's standard output stream, typically used to emit data it produces.
no setteroverride
success Future<bool>
Whether the script succeeded or failed (that is, whether it emitted an exit code of 0).
no setterinherited

Methods

combineOutput() Stream<List<int>>
Returns a stream that combines both stdout and stderr the same way they'd be displayed in a terminal.
inherited
kill([ProcessSignal signal = ProcessSignal.sigterm]) bool
Sends a ProcessSignal to terminate the process.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
release() Future<void>
Emits all buffered output to stdout and stderr.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator >(StreamConsumer<List<int>> consumer) Future<void>
Shorthand for script.stdout.pipe(consumer).
inherited
operator |(Object other) Script
Pipes this script's stdout into other's stdin.
inherited