spown
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

spown npm

Spawn child process.

Install

$ yarn add spown

Usage

type TSpawnChildProcessOptions = {
  argv0?: string,
  cwd?: string,
  env?: NodeJS.ProcessEnv,
  stdin?: Stream | null,
  stdout?: Stream | null,
  stderr?: Stream | null,
  uid?: number,
  gid?: number,
  serialization?: 'json' | 'advanced'
}
 
const spawnChildProcess: (command: string, options?: TSpawnChildProcessOptions) => Promise<{
  stdout: string | null,
  stderr: string | null
}>
type TSpawnChildProcessStreamOptions = {
  argv0?: string,
  cwd?: string,
  env?: NodeJS.ProcessEnv,
  stdin?: Stream | null,
  stdout?: Stream | null,
  stderr?: Stream | null,
  shouldCreateIpcChannel?: boolean,
  uid?: number,
  gid?: number,
  serialization?: 'json' | 'advanced'
}
 
const spawnChildProcessStream: (command: string, options?: TSpawnChildProcessStreamOptions) => ChildProcess
import { spawnChildProcess, spawnChildProcessStream } from 'spown'
import { unchunkString } from 'unchunk'
 
console.log(
  await spawnChildProcess('ls /')
)
// {
//   stdout: 'Applications  Library  System  …',
//   stderr: ''
// }
 
try {
  await spawnChildProcess('ls /foo')
} catch (e) {
  console.error(e.message)
  // ls: cannot access '/foo': No such file or directory
  console.error(e.exitCode)
  // 2
}
 
const childProcess = spawnChildProcessStream('ls /foo')
const stderr = await unchunkString(childProcess.stderr)
 
console.log(stderr)
// ls: cannot access '/foo': No such file or directory

Readme

Keywords

Package Sidebar

Install

npm i spown

Weekly Downloads

66,129

Version

0.1.2

License

MIT

Unpacked Size

12.2 kB

Total Files

18

Last publish

Collaborators

  • fosimus
  • psxcode
  • deepsweet