coreybutler / coreybutler/node-windows

list + kill behavior not as reliable in 1.x-beta, as in 0.1.11

Open
#303 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.9k
Forks
368
PR merge metrics
No merged PRs in 30d

Description

I'm trying to modernize some code for work, and noticed a lot of .list & .kill commands to find & terminate errant processes. It appears in the latest 1.x beta, the list function doesn't correctly pass PIDs in a way the kill function understands. I've provided some obfuscated code for your review. Thanks!

```
const wincmd = require('node-windows')
const userprogramProc = ["userprogram.exe", "userprogram2.exe"]
// returns the pids of exes that match userprogramProc
async function checkuserprogramProcesses(svc){
let svcPromise
if (svc) {
svcPromise = Promise.resolve(svc)
} else {
svcPromise = new Promise((resolve) => wincmd.list((svc) => resolve(svc)))
}
let pids = await svcPromise.then(svc => {
const processes = _.filter(svc, (p) => userprogramProc.includes(p.ImageName))
return _.map(processes, 'PID')
})
return pids
}
async function closeuserprogramProcesses (){
await closeProcessIfRunning("otherprogram.exe", false)
let pids = await checkuserprogramProcesses()
return Promise.map(pids, (pid) => new Promise((resolve) => wincmd.kill(pid, true, () => {
logger.info('closed userprogram process')
return resolve()
})), {concurrency: 2})
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.