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