【问题标题】:Nodejs spawn child process timingNodejs 产生子进程的时间
【发布时间】:2016-12-17 19:05:51
【问题描述】:

我正在尝试编写一个 nodejs 脚本来生成一个观察者进程并生成另一个进程来启动我的开发服务器,但我需要观察者完成构建,在开发服务器启动之前开始观察。我尝试过使用超时,但很难判断构建何时完成。

var spawn = require('child_process').spawn
fileWatcher = spawn('cmd', [args'], { stdio: 'inherit' })
setTimeout(function() {
 devServer = spawn('node', ['server/index.js'], { stdio: 'inherit' })
},20000)

有没有办法知道任何一个子进程何时没有输出任何数据,至少我会知道它已经完成/等待输入。

【问题讨论】:

    标签: node.js build child-process


    【解决方案1】:

    如果 { stdio: 'inherit' } 不是必需的,那么您可以使用如下内容:

    var spawn = require('child_process').spawn;
    args = ['-f', 'test.log'];
    fileWatcher = spawn('tail', ['-f', 'abc.log']);
    fileWatcher.stdout.once('data', function(data){
      console.log("Spawning dev server");
      devServer = spawn('node', ['server.js'], { stdio: 'inherit' });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-16
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      相关资源
      最近更新 更多