views:

400

answers:

3

I have a JAVA application that launches (using ProcessBuilder) another JAVA application like this:

String val = "something";
ProcessBuilder processBuilder = new ProcessBuilder("java", "-classpath", dir, appName, val);
Process p = processBuilder.start();

Now, this works fine, appName is launched with the parameter val and it runs and works ... great ... the problem is no Console Window appears ... appName does a LOT of outputting to the console and we need to see it ... how can I start the process with a console?

I am trying stuff like ("CMD.exe", "java", "-classpath", dir, appName, val), etc... but I can't get it right ...

Also, I can't redirect the streams, my program can actually start 5-10 of these appName's, each should have their own console window showing their own information.

Any help would be much appreciated. Thanks,

A: 

console windows are generally not the most reliable form of logging. they only store a set amount of information (buffer) and can behave differently across platforms.

i strongly suggest logging to a file using something like log4j and if you need to see it real time use a tail like program (i see you're using windows).

in addition to this, seeing as you want the windows visible at all times and launching a tail program for each log might be annoying, i'd write my own log window in java swing.

the basic idea is to not rely on the OS too much.

pstanton
A: 

Tried Runtime.getRuntime().exec("cscript java -classpath ..."); ?

Anyway, consider using a logging framwork (log4j, commons-logging), because opening 5 consoles is not the most clever thing to do.

Bozho
A: 

The problem is - I need to keep a list of these running processes - in like a table, using ProcessBuilder allows me to keep a handle to it ... use RunTime.getRuntime.exe doesn't actually return anything I can keep...

So that later, if need be, I can kill it ....

Shaitan00
i recommend you keep it all "in house" ie in java. why do you need more than one process? why not use multiple threads. ps: you should comment on your question, or edit your question to add more info.
pstanton