【发布时间】:2022-01-21 15:36:18
【问题描述】:
我正在使用 child_process 的 exec 函数从 NodeJS 执行 Python 程序,我希望在单击按钮。
我正在使用 Windows11。
这是我的代码:
var process__ = undefined; // this is a global variable
function executePython(command_line_arguement){
const exec = require('child_process').exec;
process__=exec(`python program.py "${command_line_arguement}"`, { encoding: 'utf-8',detached : true }, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}, ${stderr}`);
}else{
console.log(stdout);
}
});
function onButtonClick(){
process__.kill('SIGINT');
}
但是,这不会似乎停止或杀死被触发的python进程。
任何关于如何进行的指导都将是可观的。
提前致谢!
【问题讨论】:
标签: python node.js exec child-process kill-process