有没有一种方法可以从javascript代码内部调用Windows批处理文件?还是通过任何节点包进行以下操作的其他健康方法?
scripts.bat
ECHO "JAVASCRIPT is AWESOME"
PAUSE
scripts.js
// Code to read and run the batch file //
在命令提示符下:
C:/> node scripts.js
最佳答案
一种方法是使用child_process。您只需要传递要执行的文件。
const execFile = require('child_process').execFile;
const child = execFile('scripts.bat', [], (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log(stdout);
});