Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
unquietwiki opened this issue Dec 15, 2021 · 0 comments
Open

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

unquietwiki opened this issue Dec 15, 2021 · 0 comments

Comments

@unquietwiki
Copy link

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})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant