Execute a Unix Command with Node.js


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // http://nodejs.org/api.html#_child_processes
  2. var sys = require('sys')
  3. var exec = require('child_process').exec;
  4. var child;
  5.  
  6. // executes `pwd`
  7. child = exec("pwd", function (error, stdout, stderr) {
  8. sys.print('stdout: ' + stdout);
  9. sys.print('stderr: ' + stderr);
  10. if (error !== null) {
  11. console.log('exec error: ' + error);
  12. }
  13. });

URL: execute-a-unix-command-with-node-js

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.