GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   SysAdmin's, How to Get Process ID on Windows? (https://gfy.com/showthread.php?t=917528)

WiredGuy 07-23-2009 09:51 AM

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

Ice 07-23-2009 09:59 AM

Can you hit me up on icq

Machete_ 07-23-2009 10:09 AM

you can do it using http://www.autohotkey.com/

run, %v_program% newpid

And then pick it up using ahk_pid %newpid%

pstation 07-23-2009 10:10 AM

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()

Machete_ 07-23-2009 10:12 AM

or if you are doing it on a server, you can use Powershell http://blogs.msdn.com/powershell/arc...owershell.aspx

WiredGuy 07-23-2009 10:30 AM

I was really hoping on finding a simple Windows command to echo the pid rather than rewriting this all in powershell.
WG

pstation 07-23-2009 10:35 AM

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