Skip to content

Instantly share code, notes, and snippets.

@nojaf
Created February 26, 2015 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nojaf/44ab25cfa3a3da319b97 to your computer and use it in GitHub Desktop.
Save nojaf/44ab25cfa3a3da319b97 to your computer and use it in GitHub Desktop.
Node (v0.12) run child processes and receive output
var child_process = require("child_process");
command("dir");
commandSync("ping 127.0.0.1");
function command(cmd){
var child = child_process.exec(cmd);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
return child;
}
function commandSync(cmd){
var childSync = child_process.execSync(cmd);
process.stdout.write(childSync);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment