我有一個執行流程的功能:
static async runTest() { await process.exec(`start ${currentDir}/forward.py`); }
runTest();
python腳本將繼續運行,直到它被殺死,我目前不知道該怎么做。所以簡而言之,我想在某個時候手動終止這個程序。我該怎么做?謝謝!
uj5u.com熱心網友回復:
exec 回傳值是一個子行程物件,您可以隨時通過呼叫 .kill() 函式來終止它。更多資訊,你可以參考這個
https://nodejs.org/api/child_process.html
我使用簡單的超時演示了 kill 函式。
const { exec } = require('child_process');
let childprocess = exec('python a.py', (error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
console.log(`stdout:\n${stdout}`);
});
setTimeout(() => { //Example killing
childprocess.kill()
}, 2000);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/408515.html
標籤:
上一篇:“FormGroup”型別上不存在Angular13屬性
下一篇:在子組件中改變陣列道具是否有效?
