Created
December 15, 2017 06:03
-
-
Save markterence/88d34a921897a7e0b645bb7f3131705d to your computer and use it in GitHub Desktop.
simple usage of exec in node js
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
// http://nodejs.org/api.html#_child_processes | |
//Sample1 | |
var sys = require('sys') | |
var exec = require('child_process').exec; | |
var child; | |
// executes `pwd` | |
child = exec("pwd", function (error, stdout, stderr) { | |
sys.print('stdout: ' + stdout); | |
sys.print('stderr: ' + stderr); | |
if (error !== null) { | |
console.log('exec error: ' + error); | |
} | |
}); | |
//Sample2 | |
var sys = require('sys') | |
var exec = require('child_process').exec; | |
function puts(error, stdout, stderr) { sys.puts(stdout) } | |
exec("ls -la", puts); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment