Question

I'm trying to run instances of console application ( written on cpp ) from nodejs by using child_process . Here is the code :

function startSingleApp() {
    console.log("startSingleApp entered");

    var exec = childProcess.exec;
    var appOut;
    exec("./ConsoleApplication.exe"  ,function callback(error, stdout, stderr){
        appOut = stdOut;
        console.log("started console app");
    });
};

And ConsoleApplication4 only prints strings ( cout<<"some string") Expected behavior : for each instance of ConsoleApplication4 - console window opened and new process created Actual behavior : no console window , no process create . But "started console app" string printed on console ( from which nodejs app started ) ConsoleApplication.exe located in same folder where nodejs app located If replace ConsoleApplication.exe by some window app ( notepad or calc) - it works. The question - what is missing in this code ? Do I need manually catch console out from the consoleapplication ?
Your help will be helpful.
Thaks in advance

Était-ce utile?

La solution

If you run a console application from a console, it’s still going to run in the same console. The Windows console is just a convenience that opens automatically when you’re running a console application through Explorer.

You can try it yourself: open cmd.exe first, then run ConsoleApplication.exe. It won’t open a new window; the output will appear beneath your prompt. And then you’ll get another one.

If you want a window to show up, you can run cmd manually:

exec("cmd /c ConsoleApplication.exe", function callback(error, stdout, stderr) {
    appOut = stdOut;
    console.log("started console app");
});

Autres conseils

You can use start to make a new console window like this:

exec("start ConsoleApplication.exe", ....)

and add a line in your C++:

getch();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top