Why do I get no IO exception ?

Z

zero

Hallo,

In an application I have the following block of code:

=== import ===
if ( ok.equals(cmd) ) { // Process the
selection
String selection =
firmsTable.get((byte)choiceList.getSelectedIndex())
;
try {
ProcessBuilder pk =
new ProcessBuilder("java", "Greetings");
Map<String, String> env = pk.environment();
env.put("LANG", myLocale.toString());
env.put("FIRMACODE", selection.substring(2, 5));
env.put("FIRMANAAM", selection.substring(5 ))

Process ppk = pk.start();
} catch (IOException ioex) { System.err.println(ioex); }
Runtime runtime = Runtime.getRuntime();
runtime.exit(0);
}
=== tropmi ===

When "Greetings" does not exist, I would expect an IO exception. But I
get nothing. Why?

Groetjes,

Hans.

As far as I can tell, this code just runs java with "Greetings" as
argument, right? So why would you expect an IOException? As long as the
java executable exits, this code doesn't care about the rest of the
argument list.
 
J

Johannes Beekhuizen

Hallo,

In an application I have the following block of code:

=== import ===
if ( ok.equals(cmd) ) { // Process the selection
String selection =
firmsTable.get((byte)choiceList.getSelectedIndex());
try {
ProcessBuilder pk =
new ProcessBuilder("java", "Greetings");
Map<String, String> env = pk.environment();
env.put("LANG", myLocale.toString());
env.put("FIRMACODE", selection.substring(2, 5));
env.put("FIRMANAAM", selection.substring(5 ))
Process ppk = pk.start();
} catch (IOException ioex) { System.err.println(ioex); }
Runtime runtime = Runtime.getRuntime();
runtime.exit(0);
}
=== tropmi ===

When "Greetings" does not exist, I would expect an IO exception. But I get
nothing. Why?

Groetjes,

Hans.
 
R

Roedy Green

When "Greetings" does not exist, I would expect an IO exception. But I get
nothing. Why?

You might possibly expect something if java.exe did not exist (use
explicit extensions in Windows), but once that program fires up, it is
a separate process, Any troubles it has, e.g. finding the Greetings
class, all you are going to find out is by the return code.

I hope you are just experimenting. If all you want to do in run
Greetings, just invoke method Greetings.main( new String [0] );
 
O

opalpa

What Roedy is saying (assuming that Greetings and all other
applications are java too) you can invoke them within the JVM you are
in. Instead of executing in the operating system you can invoke the
main method on the classes you are interested in. (But you may want to
instantiate a Greetings object and then call some method). Because
you're not doing that I get a feeling that some of the stuff you invoke
is not Java classes but some other language executables.
 
O

opalpa

What Roedy is saying (assuming that Greetings and all other
applications are java too) you can invoke them within the JVM you are
in. Instead of executing in the operating system you can invoke the
main method on the classes you are interested in. (But you may want to
instantiate a Greetings object and then call some method). Because
you're not doing that I get a feeling that some of the stuff you invoke
is not Java classes but some other language executables.

http://www.geocities.com/opalpaweb/
 
J

Johannes Beekhuizen

Hallo,

Op 06 Jan 06 schreef zero aan All:
z> As far as I can tell, this code just runs java with "Greetings" as
z> argument, right? So why would you expect an IOException? As long as
z> the java executable exits, this code doesn't care about the rest of the
z> argument list.

Ah, stupid me! Why didn't I see this? Thank you very much for waking me up.

Groetjes,

Hans.
 
J

Johannes Beekhuizen

Hallo Roedy,

Op 06 Jan 06 schreef Roedy Green aan All:
RG> You might possibly expect something if java.exe did not exist (use
RG> explicit extensions in Windows), but once that program fires up, it is
RG> a separate process, Any troubles it has, e.g. finding the Greetings
RG> class, all you are going to find out is by the return code.

OK, so I'll have to find out about retrieving the return code...

RG> I hope you are just experimenting. If all you want to do in run
RG> Greetings, just invoke method Greetings.main( new String [0] );

The idea is that this application will be able to start other applications
depending on the choice of the user. The "Greetings" is just used as an
example to get the mechanism correct. If you think there's a beter way to do
that, I won't mind if you tell me :)

Thanks for your help.

Groetjes,

Hans.
 
R

Roedy Green

The idea is that this application will be able to start other applications
depending on the choice of the user. The "Greetings" is just used as an
example to get the mechanism correct. If you think there's a beter way to do
that, I won't mind if you tell me :)

If you are starting Java apps, you can use Class.forName. If you are
starting apps written in something else, you would need to use exec.

ClassForName will be much quicker since the program will run in the
same JVM.

See http://mindprod.com/jgloss/exec.html
http://mindprod.com/jgloss/classforname.html
 
R

Roedy Green

OK, thank you. I'll study this and see if I can get it to work.
I hava a question already: I prefer to pass parameters to the spawned
applications by environment variables rather than parameters. I have not seen
a way [yet] to do this with this construction. Is it possible at all?

See http://mindprod.com/jgloss/exec.html to pass environment variables
to a spawned program.
 
J

Johannes Beekhuizen

Hallo,

Op 06 Jan 06 schreef (e-mail address removed) aan All:

o> Instead of executing in the operating system you can invoke the main
o> method on the classes you are interested in. (But you may want to
o> instantiate a Greetings object and then call some method). Because
o> you're not doing that I get a feeling that some of the stuff you
o> invoke is not Java classes but some other language executables.

Wrong :) I am somebody who was a reasonably handy programmer in Fortran,
Pascal en Cobol under MS-Dos and on main frames who suddenly has to work with
Java under Linux. That requires a rather different way of thinking...

Groetjes,

Hans.
 
J

Johannes Beekhuizen

Hallo Roedy,

Op 06 Jan 06 schreef Roedy Green aan All:
RG> If you are starting Java apps, you can use Class.forName. If you are
RG> starting apps written in something else, you would need to use exec.

OK, thank you. I'll study this and see if I can get it to work.
I hava a question already: I prefer to pass parameters to the spawned
applications by environment variables rather than parameters. I have not seen
a way [yet] to do this with this construction. Is it possible at all?

Groetjes,

Hans.
 
T

Thomas Weidenfeller

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top