Search code examples
node.jswindowsexecchild-process

Open Windows child_process exec in its own console window, from Node JS


I am under Windows and Node JS/Express, using installed 'child_process' module. I need to launch the executable 'c:\test\test.exe' - a windows console application - from Node JS.
I can launch non-console applications but I'm having problems with the console ones;
e.g. I have tried the simple statement:

const childProcess = require('child_process');
..............    
childProcess.execFile(process.env.C_APP_EXEC_NAME);

which works fine with 'full_path\WINWORD.EXE' but not with c:\test\test.exe.
I want to add that I need to have the console opened since the test.exe interacts with the user through it. Thanks for help


Solution

  • Here it is by bringing together several pieces, Node JS- and Windows-related: the call should be

    childProcess.exec("start cmd @cmd /k " + process.env.C_APP_EXEC_NAME);
    

    The process.env.C_APP_EXEC_NAME is either the full path of the test.exe file or its relative path to the Node JS application's root directory HTH