Starting and Stopping an External Process

D

DevNull

Hello Everyone,
After realizing I'm spending way to much time playing games I decided
to create a Tea-Timer application.
The purpose of the application is to launch another application such
as solitaire or wow or what have you. Then countdown to a specified
time, and when the time limit is reached kill the game.

I have it all going now with the exception of killing the specified
game.
The assumption that I made (evidently a bad assumption on my part),
was that simply exiting the java app would kill the running child
app. This does not seem to be the case.
Can anyone point me in the right direction on how best to kill off the
application once the time runs out?

Thanks in advance!
 
O

Oliver Wong

DevNull said:
Hello Everyone,
After realizing I'm spending way to much time playing games I decided
to create a Tea-Timer application.
The purpose of the application is to launch another application such
as solitaire or wow or what have you. Then countdown to a specified
time, and when the time limit is reached kill the game.

I have it all going now with the exception of killing the specified
game.
The assumption that I made (evidently a bad assumption on my part),
was that simply exiting the java app would kill the running child
app. This does not seem to be the case.
Can anyone point me in the right direction on how best to kill off the
application once the time runs out?

Try reading the javadocs for the classes you are using.

For example, if you are using the Process class, you should read
http://java.sun.com/javase/6/docs/api/java/lang/Process.html

- Oliver
 
A

alexandre_paterson

Hello Everyone,
After realizing I'm spending way to much time playing games I decided
to create a Tea-Timer application.
The purpose of the application is to launch another application such
as solitaire or wow or what have you. Then countdown to a specified
time, and when the time limit is reached kill the game.

I have it all going now with the exception of killing the specified
game.

So I assume you already now how to launch an external process
from Java...

The assumption that I made (evidently a bad assumption on my part),
was that simply exiting the java app would kill the running child
app. This does not seem to be the case.
Can anyone point me in the right direction on how best to kill off the
application once the time runs out?

If you're playing WoW on Linux or OS X, "kill -9" will do the job
in a cruel way... All you need to know is the PID of the process,
which you can easily find using the output of ps.

If you're on Windows, then I'd recommend the free and
excellent "pskill.exe" for http://www.sysinternals.com
(for pskill.exe you simply need the name of the process,
which should always be the same for, say, WoW).

I'm using it since years for several Windows version and it
works like wonder.

That said, launching a Java app and keeping a JVM running
just as a timer seems overkill. I'd go with a bash/shell script
running in the background.
 
A

alexandre_paterson

replying to myself...

As explained in the Process JavaDocs, as you're in
control of the process you created Process's destroy()
method MAY do what you want. However in won't
work for every process launched by Java' Process
facility (this is explained in the JavaDocs).

So, check if Process's destroy() method works *in
your case*... Otherwise check kill / pskill.exe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top