Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not know why the pop-up a new window, is it a node bug #9367

Closed
yuchonghua opened this issue Oct 30, 2016 · 6 comments
Closed

Do not know why the pop-up a new window, is it a node bug #9367

yuchonghua opened this issue Oct 30, 2016 · 6 comments
Labels
child_process Issues and PRs related to the child_process subsystem. question Issues that look for answers.

Comments

@yuchonghua
Copy link

yuchonghua commented Oct 30, 2016

Do not know why the pop-up a new window, is it a node bug
node_bug
sysinfo

run.js

console.log("begin daemon");
process.title = "start_daemon";
//child_process模块
const child_process = require('child_process');
const spawn = require('child_process').spawn;
const fs = require('fs');

if (process.env.TRAVIS) {
    // Redirect DDV
    //  internal err and out to STDERR STDOUT when running with Travis
    out = 1;
    err = 2;
}else {
    out = fs.openSync(process.cwd()+'\\out.log', 'a');
    err = fs.openSync(process.cwd()+'\\err.log', 'a');
}
console.log(process.argv[0],[process.cwd()+"\\daemon.js"]);
var c=spawn(process.argv[0],[process.cwd()+"\\daemon.js"],{
    detached   : true,
    cwd        : process.cwd(),
    stdio      : ['ipc', out, err]
});
c.unref();
c.on("message",function  () {
    c.disconnect();
});

daemon.js

process.send('exit');
console.log("this is daemon");
process.title = "start_daemon";
//child_process模块
const child_process = require('child_process');
child_process.fork(process.cwd()+"\\master.js");

master.js

console.log("this is master");
process.title = "start_master";
//child_process模块
const child_process = require('child_process');
child_process.fork(process.cwd()+"\\worker.js");

worker.js

console.log("this is worker");
process.title = "start_worker";

var http = require('http');

var server = http.createServer(function (request, response) {
    response.writeHead(200, {
    });
    response.write("test");
    response.end();
});
server.listen(80);
console.log("Server runing at port: 80.");

This is a zip compression package, but due to the restrictions git, so the extension to the png only to upload, download, change back to the zip file and then extract, thank you
https://cloud.githubusercontent.com/assets/17898715/19836207/3f336090-9ed4-11e6-870b-7a95d745d766.png

@S-YOU
Copy link

S-YOU commented Oct 30, 2016

May be this is by design.

On Windows, setting options.detached to true makes it possible for the child process to continue running after the parent exits. The child will have its own console window. Once enabled for a child process, it cannot be disabled.

https://nodejs.org/api/child_process.html#child_process_options_detached

Use detached: false instead.

@Fishrock123 Fishrock123 added question Issues that look for answers. child_process Issues and PRs related to the child_process subsystem. labels Oct 30, 2016
@yuchonghua
Copy link
Author

Now need to be able to create a daemon thread

@S-YOU
Copy link

S-YOU commented Oct 30, 2016

In Windows, you can not run background program in command prompt, as far as I know.
Create a Windows service yourself or allow popup window or may be use used Ubuntu shell?

Edit: may be use start /b command or start "" command- http://superuser.com/q/198525/how-can-i-execute-a-windows-command-line-in-background

@yuchonghua
Copy link
Author

If I want to join the window to the service node to run, how should I do

@S-YOU
Copy link

S-YOU commented Nov 3, 2016

@yuchonghua
Copy link
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

3 participants