mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Use wmic to kill child processes
This commit is contained in:
parent
9d3082ec95
commit
a205c6d190
@ -117,8 +117,34 @@ class BufferedProcess
|
|||||||
onLines(buffered) if buffered.length > 0
|
onLines(buffered) if buffered.length > 0
|
||||||
onDone()
|
onDone()
|
||||||
|
|
||||||
|
# Kill all child processes of the spawned cmd.exe process on Windows.
|
||||||
|
#
|
||||||
|
# This is required since killing the cmd.exe does not terminate child
|
||||||
|
# processes.
|
||||||
|
killAllChildProcessesOnWindows: ->
|
||||||
|
parentPid = @process.pid
|
||||||
|
cmd = 'wmic'
|
||||||
|
args = [
|
||||||
|
'process'
|
||||||
|
'where'
|
||||||
|
"(ParentProcessId=#{parentPid})"
|
||||||
|
'get'
|
||||||
|
'processid'
|
||||||
|
]
|
||||||
|
|
||||||
|
wmicProcess = ChildProcess.spawn(cmd, args)
|
||||||
|
output = ''
|
||||||
|
wmicProcess.stdout.on 'data', (data) -> output += data
|
||||||
|
wmicProcess.stdout.on 'close', ->
|
||||||
|
pidsToKill = output.split('\n')
|
||||||
|
.filter (pid) -> /^\d+$/.test(pid)
|
||||||
|
.map (pid) -> parseInt(pid)
|
||||||
|
.filter (pid) -> not pid is parentPid
|
||||||
|
process.kill(pid) for pid in pidsToKill
|
||||||
|
|
||||||
# Public: Terminate the process.
|
# Public: Terminate the process.
|
||||||
kill: ->
|
kill: ->
|
||||||
@killed = true
|
@killed = true
|
||||||
|
@killAllChildProcessesOnWindows() if process.platform is 'win32'
|
||||||
@process.kill()
|
@process.kill()
|
||||||
@process = null
|
@process = null
|
||||||
|
Loading…
Reference in New Issue
Block a user