Вопрос

I have the following node.js code:

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();

however the close method never gets calls.

The end result I am looking for is that I spwan a process and the the script waits for that child processs to finish (which waitpid() is doing correctly). I want the output/err of the child process to be display to the screen (which the stdio config is doing correctly). I also want to perform code on the close of the child process which I was going to do in the close event (also tried exit), but it does not fire.

Why is the event not not firing?

Это было полезно?

Решение 2

Looking at waitpid() I found out that it returns an object with the exitCode. I changed my code so that I just perform certain actions based on what the value of the exitCode is.

Другие советы

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.

You can specify the signal while Kill() call.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top