首页 > 解决方案 > 用 JS 关闭 py 终端

问题描述

我想用 Javascript 关闭一个 py 终端,但我不知道如何杀死一个特定的进程

如果有人可以帮助我,那就太酷了

var kill  = require('tree-kill');
const spawn = require('child_process').spawn;

var scriptArgs = ['myScript.sh', 'arg1', 'arg2', 'youGetThePoint'];
var child = spawn('sh', scriptArgs);

// some code to identify when you want to kill the process. Could be
// a button on the client-side??
button.on('someEvent', function(){
    // where the killing happens
    kill(child.pid);
});

我在 stackoverflow 上找到了这个,但我不太明白,文件名为“UP.py”,所以如果我不知道正确的 PID,我该如何关闭它

标签: javascriptpythonterminal

解决方案


推荐阅读