« get me outta code hell

kill-process.js « src - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/kill-process.js
blob: c6a3349696278a4c5be51df733637f9a4c6bf8f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict'

const { spawn } = require('child_process')
const commandExists = require('./command-exists')
const promisifyProcess = require('./promisify-process')

module.exports = async function killProcess(proc) {
  // Windows is stupid and doesn't like it when we try to kill processes.
  // So instead we use taskkill! https://stackoverflow.com/a/28163919/4633828

  if (await commandExists('taskkill')) {
    await promisifyProcess(
      spawn('taskkill', ['/pid', proc.pid, '/f', '/t']),
      false
    )
  } else {
    proc.kill()
  }
}