From: Hakan on

Which is the best way to get the process ID on Windows after spawning a
Process object with the Runtime.getRuntime.exec method? A search on the
web says that Java has no direct way of doing it, and then several
different ways to do it are presented. Thanks.



--
Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet
Die Signatur l��t sich nach Belieben anpassen ;-)
From: John B. Matthews on
In article <1280082152.94(a)user.newsoffice.de>, Hakan <H.L(a)softhome.net>
wrote:

> Which is the best way to get the process ID on Windows after spawning
> a Process object with the Runtime.getRuntime.exec method? A search on
> the web says that Java has no direct way of doing it, and then
> several different ways to do it are presented. Thanks.

On my platform , I've used `ps` and `awk` from a bash script to do this;
jps looks a little more portable, although the format is subject to
change in future releases:

What criteria are you using to evaluate the approaches you've examined
so far?

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Arne Vajhøj on
On 25-07-2010 14:22, Hakan wrote:
> Which is the best way to get the process ID on Windows after spawning a
> Process object with the Runtime.getRuntime.exec method? A search on the
> web says that Java has no direct way of doing it, and then several
> different ways to do it are presented. Thanks.

Write something that start a process via JNI and CreateProcess.

It is not portable, but your problem definition is not portable.

Arne
From: Owen Jacobson on
On 2010-07-25 21:59:23 -0400, Arne Vajh�j said:

> On 25-07-2010 14:22, Hakan wrote:
>> Which is the best way to get the process ID on Windows after spawning a
>> Process object with the Runtime.getRuntime.exec method? A search on the
>> web says that Java has no direct way of doing it, and then several
>> different ways to do it are presented. Thanks.
>
> Write something that start a process via JNI and CreateProcess.
>
> It is not portable, but your problem definition is not portable.
>
> Arne

Seconding this; you need to use platform-specific features to fiddle
with process control beyond "start a process" and "wait for it to end",
so you might as well use a language suited to the target platform. Use
..Net, not Java, if you need to do this on Windows.

-o