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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 07-23-2009, 09:51 AM   #1
WiredGuy
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.

Last edited by WiredGuy; 07-23-2009 at 09:52 AM..
WiredGuy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-23-2009, 09:59 AM   #2
Ice
Confirmed User
 
Ice's Avatar
 
Join Date: Nov 2002
Location: Sunny California
Posts: 26,053
Can you hit me up on icq
__________________
icq 1904905
Ice is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-23-2009, 10:09 AM   #3
Machete_
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%
Machete_ is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-23-2009, 10:10 AM   #4
pstation
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()

Last edited by pstation; 07-23-2009 at 10:11 AM..
pstation is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-23-2009, 10:12 AM   #5
Machete_
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
Machete_ is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-23-2009, 10:30 AM   #6
WiredGuy
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.
WiredGuy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-23-2009, 10:35 AM   #7
pstation
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
pstation is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.