child-process-promise
child-process-promise copied to clipboard
How to kill an exec process before it finishes?
If I start an exec process within an asynchronous function like this:
let process = await exec('sleep 3')
and then later attempt to kill that process before it finishes by doing this:
process.kill()
I get the error "TypeError: process.kill is not a function". I am able to kill a process in this manner when using the standard child_process
module with callbacks. What would be the correct way to kill an exec process before it has finished using this library?
Thanks
This would be great
You should be able to do it like this:
const promise = exec('sleep 3')
promise.childProcess.kill()
The key is to not await
the promise.