2014-03-19 21 views
0

我有以下的Node.js代碼:子進程不調用close事件

var testProcess = spawn(item.testCommand, [], { 
    cwd: process.cwd(), 
    stdio: ['ignore', process.stdout, process.stderr] 
}); 

testProcess.on('close', function(data) { 
    console.log('test'); 
}); 

waitpid(testProcess.pid); 
testProcess.kill(); 

然而close方法永遠不會調用。

我在尋找的最終結果是我spwan一個進程,腳本等待那個子進程完成(waitpid()正在做的正確)。我希望將子進程的輸出/ err顯示到屏幕上(stdio配置正在正確執行)。我還想在關閉事件(也嘗試退出)時要執行的子進程結束時執行代碼,但它不會觸發。

爲什麼事件不能解除?

回答

0

看着waitpid()我發現它用exitCode返回一個對象。我更改了我的代碼,以便根據exitCode的值執行某些操作。

0

http://nodejs.org/api/process.html

Note that just because the name of this function is process.kill, it is really just a signal sender, like the kill system call. The signal sent may do something other than kill the target process.

可以指定信號而殺()調用。