'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 1:[1]
You can use spawn as well.
const { spawn } = require('child_process');
const child = spawn('cmd.exe', ['/c', PATH_TO_EXE], { detached: true })
// Event handlers for the child process
child.on('data', (data) => {})
child.on('error', (error) => {})
child.on('close', (code) => {})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jay Wick |
