Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Outputing a program's PID  (Read 3112 times)

0 Members and 1 Guest are viewing this topic.

PPowerHouseK

  • Guest
Outputing a program's PID
« on: September 26, 2011, 10:02:31 PM »
Hello all,

I am just trying to get the PID of a running process and I think I am on the right track, however I seem to be having some syntax troubles. Hopefully someone can shed some light on this for me. Here's the line that gives me trouble. Its running on a Win7 if that helps.

Code: [Select]
FOR /F "tokens=2" %I in ('TASKLIST /NH /FI "WINDOWTITLE eq testwindow"' ) DO SET PID=%I

When I run this in cmd it outputs the text "SET PID=(the process number)", but does not actually set the value. If I run this in a script, it just terminates after this line and does not continue onward with the rest of the code.

Thanks for your time.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Outputing a program's PID
« Reply #1 on: September 26, 2011, 11:58:00 PM »
You posted this in the DOS forum.
Is this not a UNIX question?
You did not make it clear if you mean Windows or DOS.
Without details, Linux is amused.
http://www.cyberciti.biz/faq/howto-display-process-pid-under-linux-unix/

PPowerHouseK

  • Guest
Re: Outputing a program's PID
« Reply #2 on: September 27, 2011, 12:49:47 AM »
Quote
Its running on a Win7 if that helps.

I meant I was running Microsoft Windows 7, which would be Microsoft DOS. Not Unix or Linux or Macintosh. :)

PPowerHouseK

  • Guest
Re: Outputing a program's PID
« Reply #3 on: September 27, 2011, 01:38:33 AM »
Quote
C:\tmp>tasklist  |  findstr 2684
hkcmd.exe                     2684 Console                    1      3,472 K

C:\tmp>
lol, no. First of all your rude private messages are not helping you. Secondly, you need to reread my question. That is not what I was asking. Please just move on DonnaDay. I will wait for help from someone a little more knowledgeable and polite, or not at all.

PPowerHouseK

  • Guest
Re: Outputing a program's PID
« Reply #4 on: September 27, 2011, 01:55:59 AM »
Well I found what I was looking for here: http://it.toolbox.com/blogs/database-solutions/kill-a-process-in-windows-bat-19875 In case someone else needs the answer in the future.

Thanks anyhow for the sarcasm and rude messages guys, I'll be sure to come back and recommend this place to my friends...not.

Salmon Trout

  • Guest
Re: Outputing a program's PID
« Reply #5 on: September 27, 2011, 02:34:35 AM »
Code: [Select]
FOR /F "tokens=2" %I in ('TASKLIST /NH /FI "WINDOWTITLE eq testwindow"' ) DO SET PID=%I

That code might work OK as a command typed in at the prompt, but as a line in a batch script, it needs the percent signs doubled up so that %I becomes %%I. This is a fundamental part of Windows command scripting that has clearly passed you by.

You got unlucky in that you had to contend with Geek-9PM who is getting increasingly erratic, (but cannot help it) and also DonnaDay (who is really Bill Richardson, a malicious troll, and does it on purpose). I am on vacation in Andalucia, Spain right now so naturally this part of the forum has gone downhill rapidly. A couple of points...

1. The command prompt environment in Windows NT family operating systems from Windows 2000 onwards that you are clearly using, is most definitely not "DOS". There was a command line operating system called "MS-DOS" which was last updated around 1992. This is not it.

2. The 1990s called. They want their "...not" back.

3. If you are unsatisfied, please contact the Computerhope finance department and reclaim your membership fee and posting charges.


Allan

  • Moderator

  • Mastermind
  • Thanked: 1260
  • Experience: Guru
  • OS: Windows 10
Re: Outputing a program's PID
« Reply #6 on: September 27, 2011, 05:49:57 AM »
lol, no. First of all your rude private messages are not helping you. Secondly, you need to reread my question. That is not what I was asking. Please just move on DonnaDay. I will wait for help from someone a little more knowledgeable and polite, or not at all.
That post was by someone who has been banned multiple times. I've deleted the post and sorry for the inappropriate PM's he sent to you.