talira

cross-spawn

Cross-platform child_process spawn and spawnSync for Node.js

open sourceMITfree

cross-spawn is a drop-in replacement for Node.js's child_process spawn and spawnSync that works the same on Windows as on Unix. On Windows it handles what Node's own spawn gets wrong: PATHEXT, shebangs, commands with spaces or POSIX relative paths, and the command shims in node_modules/.bin, escaping arguments the way the Microsoft C runtime parses them. Install it from npm as cross-spawn.

Problems it solves

  • my Node.js script that spawns npm works on Mac but fails on Windows
  • run a command from node_modules/.bin in a child process on Windows
  • spawn a child process in Node without hand-escaping shell arguments

Features

  • drop-in replacement for spawn and spawnSync
  • handles PATHEXT and shebangs on Windows
  • commands with spaces and relative paths
  • node_modules/.bin command shims
  • Windows argument escaping by Microsoft C runtime rules

Limitations

  • With options.shell, all of its fixes are turned off, as in Node.js.1

Alternatives

The same job

These do what cross-spawn does.

  1. Execa Process execution for humans: run subprocesses from Node.js without shell escaping

Compare cross-spawn with the top 3