node.js执行shell命令

nodejs功能强大且多样,不只是可以实现 服务器端 与 客户端 的实时通讯,另一个功能是用来执行shell命令

 

首先,引入子进程模块

var process = require('child_process');

 

然后,调用该模块暴露出来的方法exec

process.exec('shutdown -h now',function (error, stdout, stderr) {
        if (error !== null) {
          console.log('exec error: ' + error);
        }
});

回调函数非必须!

 

posted @ 2015-09-09 14:32  goodup  阅读(28429)  评论(0编辑  收藏  举报

如有不对之处,欢迎指出,一起成长