Node.js and Jake - How to call system commands synchronously within a task?

ぐ巨炮叔叔 提交于 2019-12-03 08:00:37

I found the answer to my own question by re-rereading Matthew Eernisse's post. For those wondering how to do it:

var exec = require('child_process').exec;

desc('first task');
task('first', [], function(params) {
  exec('long running system command', function() {
    complete();
  });
}, true); // this prevents task from exiting until complete() is called

desc('second task');
task('second', ['first'], function(params) {
  // do something dependent on the completion of 'first' task
});

Just for future reference, I have a synchronous exec module with no other dependencies.

Example:

var allsync = require("allsync");
allsync.exec( "find /", function(data){
    process.stdout.write(data);
});
console.log("Done!");

In the above exampale, Done is only printed after the find process exists. The exec function essentially blocks until complete.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!