![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Pounding Googlebot
Industry Role:
Join Date: Aug 2002
Location: Canada
Posts: 34,460
|
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
__________________
I play with Google. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Nov 2002
Location: Sunny California
Posts: 26,053
|
Can you hit me up on icq
__________________
icq 1904905 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
WINNING!
Industry Role:
Join Date: Oct 2002
Posts: 14,579
|
you can do it using http://www.autohotkey.com/
run, %v_program% newpid And then pick it up using ahk_pid %newpid% |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: Jul 2003
Location: chicago
Posts: 1,135
|
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() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
WINNING!
Industry Role:
Join Date: Oct 2002
Posts: 14,579
|
or if you are doing it on a server, you can use Powershell http://blogs.msdn.com/powershell/arc...owershell.aspx
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Pounding Googlebot
Industry Role:
Join Date: Aug 2002
Location: Canada
Posts: 34,460
|
I was really hoping on finding a simple Windows command to echo the pid rather than rewriting this all in powershell.
WG
__________________
I play with Google. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Jul 2003
Location: chicago
Posts: 1,135
|
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |