Created
February 26, 2015 09:07
-
-
Save nojaf/44ab25cfa3a3da319b97 to your computer and use it in GitHub Desktop.
Node (v0.12) run child processes and receive output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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