![]() |
SysAdmin's, How to Get Process ID on Windows?
I'm converting a linux shell script into a Windows batch file and I'm having a hard time figuring out how to return the process ID of a program I just launched. I run this program in an infinite loop in the batch script so I need to get the process ID right after I launch it to keep track of which pid is with which session (so dumping tasklist won't work).
Unix Example: java -jar Keywords.jar & echo $! On Linux $! is the pid. This is being launched from a batch file so how can I capture the pid on a Windows environment right after I launch? WG |
Can you hit me up on icq
|
you can do it using http://www.autohotkey.com/
run, %v_program% newpid And then pick it up using ahk_pid %newpid% |
I dont believe there's an easy way to do this, from a straight batch script at least.
I suppose you could write a powershell script and use System.Diagnostics.Process to basically encapsulate the process and control it that way. then you could just call process.Start() and process.Close() |
or if you are doing it on a server, you can use Powershell http://blogs.msdn.com/powershell/arc...owershell.aspx
|
I was really hoping on finding a simple Windows command to echo the pid rather than rewriting this all in powershell.
WG |
no need to rewrite it entirely.
you can just run something like ... powershell "$p = [diagnostics.process]::start('calc.exe');echo $p.Id" straight from cmd.exe or your batch file and it'll start the process and spit out the pid |
All times are GMT -7. The time now is 09:56 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123