child-process-promise icon indicating copy to clipboard operation
child-process-promise copied to clipboard

How to kill an exec process before it finishes?

Open yowzadave opened this issue 6 years ago • 2 comments

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

yowzadave avatar Oct 12 '17 14:10 yowzadave

This would be great

BebeSparkelSparkel avatar Jan 26 '18 01:01 BebeSparkelSparkel

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.

KaidenR avatar May 14 '18 23:05 KaidenR