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