ProcessBuilder.start() without waiting... Take two

  • Thread starter alexandre_paterson
  • Start date
A

alexandre_paterson

Hi everyone,

I read and implemented what Steve Sobol described in August 2008
here in the thread called "ProcessBuilder.start() without waiting".

Tiny url to the thread archived on groups.google.com:

http://tinyurl.com/brzs2c

Basically I want the first JVM to exit *immediately* after
launching a new process (which is itself another Java process
in my case).

It has to work under Linux, OS X and Windows 2000/XP/Vista.

Under Linux I and OS X I use the "nohup" approach and under
Windows I use the launcher described by Steve Sobol:

public void launch(String path) {
String commandLine = "rundll32 shell32.dll,ShellExec_RunDLL " +
path;
String[] args = commandLine.split(" ");
ProcessBuilder pb = new ProcessBuilder(args);
try {
pb.start();
} catch (Exception exc) {
JOptionPane.showMessageDialog(null, exc.getMessage(),
"Can't launch file/program", JOptionPane.ERROR_MESSAGE);
}
}

Everything works perfectly besides one little detail on
Windows: when I invoke a Java process this way a
command-line window pops up, named "C:\Windows\system32\java.exe"
on my test systems.

This happens when I launch the first Java program from the
command line and it happens as well if I double-click on
the .jar file.

So it doesn't matter how I invoke the first JVM: when the
new JVM is launched using the rundll2/shell32.dll approach,
there's this unwanted window popping up on Windows systems.

Everything runs smoothly, but I'd like to get rid of that
window. Any idea as to how I could modify the Windows
launcher as to not have that window opened?

Note that the launcher must use the rundll32/shell32.dll
approach, for I need to exit the first JVM immediately, just
like Steve Sobol did in the original thread from August 2008.

Bonus question: on Linux and OS X, I use "nohup", which
is present on every Linux and OS X install and nohup takes
care of redirecting the output of the invoked command to a file.

But what about the Windows rundll32/shell32.dll approach, am
I supposed to deal with stdout/stderr, keeping in mind that I do
want to exit the JVM immediately. What happens to stdout/stderr
in that case?

Can I add redirection of stdout/stderr to that Windows launcher?

How should I modify the following call to both redirect stdout/stderr
to a file and to not have that unwanted command line window opening?

String cl = "rundll32 shell32.dll,ShellExec_RunDLL " + "java -
Xmx300m -jar test.jar";
String[] args = cl.split(" ");
ProcessBuilder pb = new ProcessBuilder(args);
pb.start();

Any advice appreciated,

Alex
 

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

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top