Last active
November 30, 2021 22:33
-
-
Save robinmollah/03d036be663bc3b5d76d45222d20e5cb to your computer and use it in GitHub Desktop.
Prints path of name of process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exec, spawn } = require('child_process'); | |
function getProcessPath(process_name){ | |
exec(`powershell "Get-Process ${process_name} | Format-List Path"`, (err, stdout, stderr) => { | |
if (err) { | |
console.error(err); | |
return; | |
} | |
let paths = convertToArray(stdout); | |
console.log(paths); | |
}); | |
} | |
function convertToArray(paths){ | |
let pathArray = paths.split('\n'); | |
let removedHead = pathArray.map(item => | |
item.substring(7) | |
); | |
removedHead = pathArray.map(item => | |
item.substring(0, item.length -1) | |
); | |
removedHead = removedHead.filter(item => item.length > 0); | |
return removedHead; | |
} | |
getProcessPath("node"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment