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

Forever erroneously pops up console window when executing child process calls #767

Open
jonrhall opened this issue Oct 21, 2015 · 5 comments

Comments

@jonrhall
Copy link

Working with Forever, trying to stand up a fairly simple node server which makes remote calls to a C# client. If you run the script/server directly with Node, no popup console windows will appear, but when run with Forever, every time the server wants to execute a remote command, a console window appears and then disappears after the remote command is finished.

Reproducible on:
-Windows 7 Ultimate
-Node v0.12+ or v4.0+
-npm v3
-Forever 0.15.1

Trivial code example that replicates the error:

var http = require('http'),
    exec = require('child_process').exec,
    server;

server = http.createServer(function (request, response) {
    var child;

    if (request.url != '/') {
        response.writeHead(404);
        return response.end();
    }

    response.writeHead(200, {"Content-Type": "text/plain"});

    child = exec('ping localhost -n 2', {}, function(error, stdout, stderr) {
        response.write(stdout);
    }).on('close', function(code) {
        response.end();
    });
});

server.listen(8000);

Is there some kind of bug with Forever itself, or is this some configuration option that I'm missing?

@niravpatel2008
Copy link

I am also facing this kind of issue.

below code works with node test.js but when i try run with forever start test.js it wont execute exec.

any alternative way?????

var terminal = require('child_process').spawn('bash');
terminal.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
});
terminal.on('exit', function (code) {
    console.log('child process exited with code ' + code);
});
setTimeout(function() {
    console.log('Sending stdin to terminal');
    terminal.stdin.write("whomi\n");
    terminal.stdin.write("sudo ssh instance-solr-1.us-central1-b.versatile-nomad-126504 \"sudo su | . /root/file
.sh >>/dev/null 2>/dev/null\" &\n");
    console.log('Ending terminal session');
    terminal.stdin.end();
}, 1000);

@jpek42
Copy link

jpek42 commented Apr 1, 2016

We were able to work around this by creating a separate small EXE (on Windows), which does the exec of the child program, setting the correct flags to avoid the process window. I'm not sure that the above comment is the same issue, as our child process was actually running.

@niravpatel2008
Copy link

Thanks @jpek42 , i figure out the issue actually my cmd command required terminal session for stdout. thats why its not getting executed now i have changed the way of execution of command which ignore stdout and detach child process from parent and its working fine :)

Thanks again

@r-pr
Copy link

r-pr commented Jun 14, 2019

@jonrhall: passing { windowsHide: true } instead of empty options object to exec() should fix the problem

@valyrie97
Copy link

This may be better put into another issue, as i don't want to full necro this thread. But the issue still remains for uses cases such as have a webpack watch daemon. webpack's subprocess (as well as im sure, many other packages that utilise child process) dont implement this feature, and as a developer theres no way for me to disable it without manually changing webpack code.

This definitely edges on wont fix territory, as it should be up to other packages to make code that complies with the API, however, many dont, and some form of solution would be a life saver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants