Computing.Net > Forums > Programming > kill a process from command line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

kill a process from command line

Reply to Message Icon

Name: jds
Date: March 21, 2006 at 14:58:55 Pacific
OS: windowsXP
CPU/Ram: petium III/ram 256
Comment:

Hi,
Can some one help me with this?
I scheduled a task from Win xp "Scheduled tasks". This job is will open a reflection window( an application for unix) and doing some other jobs.
I want to run it dailly. Now I am having problem:
I can run it at first time it's ok, but I can't close up that window so my scheduled task is in runing status, which blocked my next run.
I want to find out a way to kill that window.
I can see this application runing from task manager. My question is how can I kiil/ close that window from command line?
Please help. Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: jds
Date: March 21, 2006 at 15:01:05 Pacific
Reply:

or something can run this in background?


0

Response Number 2
Name: astroraptor
Date: March 21, 2006 at 20:11:42 Pacific
Reply:

You'll need to run these two commands:
tasklist
taskkill

You'll see the process using tasklist. A PID will be shown next to the process and by running taskkill you will be able to kill it. (I am assuming that the built-in commands in XP are similar to System Internal's pslist and pskill).


0

Response Number 3
Name: jds
Date: March 22, 2006 at 09:28:13 Pacific
Reply:

Thanks for your advice Astroraptor.
Yes, I could use tasklist and taskkill
but the problem is how should I do it.
Here is my situation:
I am runing an application called reflection. When it runing window shows r2win.exe is runing from my tasklist.
when I auto run my script named "test" it will bring another widow up and add another r2win.exe in tasklist ( I have serveral r2win.exe runing-- I don't want to kill then all)
So I need to use specific PID to kill the one my "test" created.. How can I tell which PID is from my "test". the PID # seems to be the latest but not the biggest.
if I use taskkill /f /im r2win.exe it would kill all of my r2win.exe section

BTW, on task manager wiondow I can see it shows my "test" is runing-- buy from task list only shows r2win.exe.

Is there anyway I can kill specific PID ( I don't know which PID is belong to my "test")

Any help is appreciated.



0

Response Number 4
Name: astroraptor
Date: March 22, 2006 at 13:12:06 Pacific
Reply:

For /F "tokens=2" %%n in ('tasklist ^| Find "r2win.exe"') Do Set Task=%%n
TaskKill %task%
Set Task=
----
Assuming that TaskList lists all processes based on launch order as does PSList, this will extract the PID and set the last found PID of r2win.exe as %task% which will then be killed by TaskKill. Careful, using Find, you must use the exact case of the EXE file in question. It should always remain the same however. If that doesn't work, try manually looking at the case of r2win.exe.


0

Response Number 5
Name: jds
Date: March 22, 2006 at 16:00:50 Pacific
Reply:

Thanks Astroraptor.
I got another issue now.
I trying to combine my script into batch script like this:
**************
echo hello -- start
test.r2w -- my script to be run
For /F "tokens=2" %%n in ('tasklist ^| Find "r2win.exe"') Do Set Task=%%n
TaskKill %task%
Set Task=
echo hello I am finished
**************
The proble is my script couldn't ended so the script is hang there
the for... part is not get excuted.
May be I'll need to use 2 seperated script?
1 my test.r2w
2 batch one to kill( end) my script?

Please help.


0

Related Posts

See More



Response Number 6
Name: astroraptor
Date: March 22, 2006 at 18:46:02 Pacific
Reply:

Have you run this from the command-line to see if an error is displayed?


0

Response Number 7
Name: jds
Date: March 25, 2006 at 20:46:37 Pacific
Reply:

Hi Astroraptor,
Sorry I was quite busy last few days.
I tried this seperately and it's working fine.
I did like this:
================
script1 "test":
echo hello
notepad.exe

script 2 kill:
For /F "tokens=2" %%n in ('tasklist ^| Find "notepad.exe"') Do Set Task=%%n
TaskKill /PID %task%
Set Task=
echo hello I have kill the test
====================================
It is working fine
But if I put it into one script it will stop at notepad.exe running -- the kill process can't get executed
To use 2 scripts is ok but I need the second script run after the first one finish -- which I don't know when the first one is done.
Please help


0

Response Number 8
Name: jds
Date: March 27, 2006 at 15:58:47 Pacific
Reply:

Thanks Astroraptor.
I got another issue now.
I trying to combine my script into batch script like this:
**************
echo hello -- start
test.r2w -- my script to be run
For /F "tokens=2" %%n in ('tasklist ^| Find "r2win.exe"') Do Set Task=%%n
TaskKill %task%
Set Task=
echo hello I am finished
**************
The proble is my script couldn't ended so the script is hang there
the for... part is not get excuted.
May be I'll need to use 2 seperated script?
1 my test.r2w
2 batch one to kill( end) my script?

Please help.


0

Response Number 9
Name: jds
Date: March 27, 2006 at 16:03:09 Pacific
Reply:

I figured I can write a marker file at the end of script 1 and in script 2 I can search if the marcker file is exist. If yes then execute the kill section.
But can youi help me on how to do the checking
Thanks a lot


0

Response Number 10
Name: jds
Date: March 28, 2006 at 11:01:52 Pacific
Reply:

I figured I can write a marker file at the end of script 1 and in script 2 I can search if the marcker file is exist. If yes then execute the kill section.
But can youi help me on how to do the checking
Thanks a lot


0

Sponsored Link
Ads by Google
Reply to Message Icon

KSH scripting help - newb... cannot resolve symbol err...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: kill a process from command line

A batch file to kill a process www.computing.net/answers/programming/a-batch-file-to-kill-a-process/12884.html

.bat removal of .exe www.computing.net/answers/programming/bat-removal-of-exe/11050.html

running java from command line www.computing.net/answers/programming/running-java-from-command-line/8040.html