Use shell commands directly from nodejs to make synchronous shell scripts.
Last updated 6 years ago by jess .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install j-shellscript 
SYNC missed versions from official npm registry.


Use shell commands directly from nodejs, nice and synchronous, so you can build easy command line scripts in node much like in Ruby.


So much like Ruby in fact, that here are the samples in coffeescript first.

shell "ls ."

And pipelines...

shell "ls . | grep lib"

Or if you us just plain Javascript

shell("ls .");

And of course, you can subshell and capture output

stuff = $("ls .")



Puts shellscript's functions on global, so you can call them without an intermediate variable or namespace, useful to make this feel a lot more like other languages with built in synchronous shelling.

shell(command, exitOnError)

This just runs a command using your current $SHELL or /bin/sh if not set. It pipes stdout and stderr into the parent, and blocks until complete. This is the workhorse make a shell script function.

If exitOnError is true, this will exit the process for any non 0 exit code. Handy if you just want to exit and avoid error checking the return object.


An object with properties:

  • pid: pid of the shelled process, now exited
  • exitCode: exit code of the shelled process
  • signalCode: signal on exit of the shelled process
  • stdout: standard out, captured as a string
  • stderr: standard error, captured as a string


Much like shell above, but instead of returning process information, returns the string that is stdout, or empty for a non-zero exit code.

$(command, args...)

In this version, if you pass args, either as a CoffeeScript splat or JavaScript array, the command will be invoked directly without a subshell. This is a tiny bit faster, and sometimes what you need if you don't want to run a shell pipeline.

Current Tags

  • 0.1.0                                ...           latest (6 years ago)

1 Versions

  • 0.1.0                                ...           6 years ago
Maintainers (2)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (0)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |