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);
        }
});

回调函数非必须!

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM