@simple-libs/child-process-utils
Version:
A small set of utilities for child process.
78 lines (59 loc) • 2.52 kB
Markdown
[![ESM-only package][package]][package-url]
[![NPM version][npm]][npm-url]
[![Node version][node]][node-url]
[![Dependencies status][deps]][deps-url]
[![Install size][size]][size-url]
[![Build status][build]][build-url]
[![Coverage status][coverage]][coverage-url]
[]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
[]: https://nodejs.org/api/esm.html
[]: https://img.shields.io/npm/v/@simple-libs/child-process-utils.svg
[]: https://www.npmjs.com/package/@simple-libs/child-process-utils
[]: https://img.shields.io/node/v/@simple-libs/child-process-utils.svg
[]: https://nodejs.org
[]: https://img.shields.io/librariesio/release/npm/@simple-libs/child-process-utils
[]: https://libraries.io/npm/@simple-libs%2Fchild-process-utils/tree
[]: https://packagephobia.com/badge?p=@simple-libs/child-process-utils
[]: https://packagephobia.com/result?p=@simple-libs/child-process-utils
[]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/simple-libs/tests.yml?branch=main
[]: https://github.com/TrigenSoftware/simple-libs/actions
[]: https://coveralls.io/repos/github/TrigenSoftware/simple-libs/badge.svg?branch=main
[]: https://coveralls.io/github/TrigenSoftware/simple-libs?branch=main
A small set of utilities for child process.
```bash
pnpm add @simple-libs/child-process-utils
yarn add @simple-libs/child-process-utils
npm i @simple-libs/child-process-utils
```
```ts
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
```