0
您好我有以下代码如何改变异步进程作为一个同步过程
function runBat(){
var exec = require('child_process').exec;
exec('C:\\Temp\\tasks\\acis\\runme.bat', function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
if (error !== null) {
console.log('exec error: ' + error);
}
});
};
runBat();
如果我是正确的exec函数是异步运行的运行。我如何将其更改为同步运行?我不希望使用任何回调
你不能。使用承诺来摆脱回调。 –
你必须使用回调。使用“异步”模块进行同步处理。 – Abie
@Abie *使用'异步'模块进行同步处理* - 不,流程中引入异步函数后,没有任何操作可以进行同步处理。 – thefourtheye