Skip to content

Instantly share code, notes, and snippets.

@markterence
Created December 15, 2017 06:03
Show Gist options
  • Save markterence/88d34a921897a7e0b645bb7f3131705d to your computer and use it in GitHub Desktop.
Save markterence/88d34a921897a7e0b645bb7f3131705d to your computer and use it in GitHub Desktop.
simple usage of exec in node js
// 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