Is there a way to completely close the cmd where the typescript file is running but unable to do so?
How can this be achieved?
console.log('This ts file must be terminate itself');
let asdef = process.pid;
let asdeff = process.ppid;
const {exec} = require('child_process')
// Terminating a PID and its child processes
exec(`Taskkill /PID ${asdef} /T`, (err, stdout, stderr) => {
if (err) {
throw err
}
console.log('stdout', stdout)
console.log('stderr', err)
})
Error Messages:
Error: Command failed: Taskkill /PID 7440 /T
ERROR: The process with PID 16320 (child process of PID 16876) could not be terminated.
Reason: The process cannot terminate itself.
ERROR: The process with PID 16876 (child process of PID 7440) could not be terminated.
Reason: One or more child processes of this process were still running.
ERROR: The process with PID 7440 (child process of PID 10880) could not be terminated.
Reason: One or more child processes of this process were still running.