Reputation: 4080
casperjs CMQ_scraper.js
Stop-Process -name phantomjs
I want to start a process (casperjs CMQ_scraper.js) and then immediately kill it.
CMQ_scraper.js shows up as phantomjs.exe in command line. however, I may have other phantomjs instances running that I don't want to kill. How can I save the PID of the new process so that I can later kill it?
Upvotes: 1
Views: 3236
Reputation: 46710
Use Start-Process
to create your process and use the -PassThru
switch. That way you can save the return into a variable.
Then you can use that variable and pipe it into Stop-Process
$specificProcess = Start-Process notepad.exe -PassThru
$specificProcess | Stop-Process
As Ansgar points out you can call the .Kill()
method as well of $specificProcess
$specificProcess.Kill()
If you really needed the PID then you can get that off the $specificProcess.ID
Upvotes: 4