0
我正在寫一個實用程序。此實用程序的一個命令是運行一個外部應用程序。NodeJS:退出父母,讓孩子活着
var child_process = require('child_process');
var fs = require('fs');
var out = fs.openSync('.../../log/out.log', 'a');
var err = fs.openSync('.../../log/err.log', 'a');
exports.Unref = function(app, argv) {
var child = child_process.spawn(app, argv, {
detached: true,
stdio: [ 'ignore', out, err ]
});
child.unref();
//process.exit(0);
};
目前:
$ utility run app --some-args // run external app
// cant enter next command while app is running
我的問題是,如果我運行此命令,「外部」應用程序運行時,終端將被鎖定。
但是終端窗口不應該被child_process鎖定。
我想運行:
$ utility run app --some-args
$ next-command
$ next-command
外部應用程序(桌面應用程序)將hisself關閉。
像這樣:
$ subl server.js // this runs Sublime Text and passes a file to the editor
$ npm start // The terminal does not locked - i can execute next command while Sublime is still running
你知道我的意思^^?
您是否嘗試追加類似'['>> ../../log/out.log','2 >> ../../log/err.log']'到' argv'而不是將兩個文件打開?這很可能是保持流程開放的原因。 – mscdex
嘿謝謝。這樣可行。我明白,但有一件事我不明白。爲什麼我給它產生這個流參數,如果他不能分離這個過程....? – Nax