1.0.0 • Published 18 days ago
@simple-libs/child-process-utils v1.0.0
@simple-libs/child-process-utils
A small set of utilities for child process.
Install
# pnpm
pnpm add @simple-libs/child-process-utils
# yarn
yarn add @simple-libs/child-process-utils
# npm
npm i @simple-libs/child-process-utils
Usage
import {
exitCode,
catchProcessError,
throwProcessError,
outputStream,
output
} from '@simple-libs/child-process-utils'
// Wait for a child process to exit and return its exit code
await exitCode(spawn())
// Returns 0 if the process exited successfully, or the exit code if it failed
// Catch error from a child process
await catchProcessError(spawn())
// Returns the error if the process failed, or null if it succeeded
// Throws an error if the child process exits with a non-zero code.
await throwProcessError(spawn())
// Yields the stdout of a child process.
// It will throw an error if the process exits with a non-zero code.
for await (chunk of outputStream(spawn())) {
console.log(chunk.toString())
}
// Collects the stdout of a child process into a single Buffer.
// It will throw an error if the process exits with a non-zero code.
await output(spawn())
// Returns a Buffer with the stdout of the process
1.0.0
18 days ago