So I have python script called main.py
#!/usr/bin/env python3
print("hello")
exit (12)
I am trying to capture the exit code via nodejs
const cp = require('child_process');
cp.exec('python main.py', (er, stdout, stderr) => {
console.log(stdout)
}).on('close', (code) => {
console.log(code)
});
This works and outputs "hello" and "12". But I need to execute python script via another cmd unit. I have tried the code below
const cp = require('child_process');
cp.exec('start cmd /k python ./main.py', (er, stdout, stderr) => {
console.log(stdout)
}).on('close', (code) => {
console.log(code)
});
But this outputs "hello" and "0" instead of "12". I have been trying to figure this out for past couple hours but not getting anywhere. What am I missing here?
Calling a another child process is not solution for me, since I am also trying to run the python script on a development unit instead on cmd