Socket
Socket
Sign inDemoInstall

better-spawn

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-spawn

a better spawn


Version published
Weekly downloads
19
increased by72.73%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 12 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc