0

在 node.js 应用程序中,我有以下代码应该启动一个名为时间戳的程序:

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

child = exec('./timestamp 207.99.83.228 5000 -p 5500 &', function (error, stdout, stderr) {
    if (error !== null) {
        console.log('exec error: ' + error);
    } else {
        // Code to be executed after the timestamp program has started
        ...
    }
}); 

但是,这不会启动时间戳程序,除非我通过以下方式调用 exec

exec('./timestamp 207.99.83.228 5000 -p 5500 &', null);

如果我省略这一行,则什么都没有,甚至没有错误消息。

因此,为了成功启动程序的一个实例,我必须调用 exec两次。这是 node.js 或 ChildProcess 类中的一些错误,还是我在这里遗漏了什么?

4

0 回答 0