1.0.4 • Published 6 years ago

better-spawn v1.0.4

Weekly downloads
13
License
MIT
Repository
github
Last release
6 years ago

Better spawn

Because child_process.exec lacks features and child_process.spawn acts weird, better-spawn was made.

It is a very simple wrapper around child_process.spawn to make opening and closing work consistently in linux and windows.
Used by script-runner

Install

npm install better-spawn

Breaking changes @1

child.closed and child.killed are now promises. The boolean states are now available at child.isClosed and child.isKilled.

Usage

spawn = require('better-spawn')
child = spawn('node', options)

Options

Nametypedefaultdescription
cwdStringprocess.cwdcurrent working directory
envObjectprocess.envenvironment variables
env.PATHStringprocess.env.PATH + ./node_modules/.binused to resolve commands
stdioSee documentation["pipe","inherit","inherit"]to control output
noOutBooleannullsets stdio[1] = "pipe"
noErrBooleannullsets stdio[2] = "pipe"
windowsVerbatimArgumentsBooleanisWindowsto support windows
detachBoolean!isWindowsto support killing on unix
PromiseFunctionglobal.Promisesupply your own Promise lib

Props

Nametypedescription
cmdStringcmd called
isKilledBooleanis child process killed
isClosedBooleanis child process closed
killedPromisefulfilled when child process killed
closedPromisefulfilled when child process closed
closeFunctioncall to kill child process

Examples

// pipe to shell without losing color
child = spawn('node')
// suppress normal output, but maintain err output
child = spawn('node',{noOut:true})
// set empty env (default in node)
child = spawn('node',{env: {PATH:""}})

Compare to other solutions

  • child_process.exec, spawns in shell but output has to be piped - color information will be lost.
  • child_process.spawn, doesn't spawn in shell, so it has to be done by hand (differs in linux and windows) Main problem is, sh won't kill its children by child.kill(), see: node#2098
  • cross-spawn-async a wrapper for child_process.spawn to support windows quirks like PATHEXT or shebangs not working
  • execa a wrapper for cross-spawn-async which adds the shell logic, to behave like child_process.exec, adds promises, modifies PATH

better-spawn doesn't support PATHEXT or shebangs on windows

License

Copyright (c) 2016 Paul Pflugradt Licensed under the MIT license.

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago