Java Forum / General / January 2006
Why do I get no IO exception ?
Johannes Beekhuizen - 01 Jan 2002 05:00 GMT 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.
zero - 06 Jan 2006 16:41 GMT > Hallo, > [quoted text clipped - 27 lines] > > 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.
 Signature Beware the False Authority Syndrome
Johannes Beekhuizen - 01 Jan 2002 05:00 GMT Hallo,
Op 06 Jan 06 schreef zero aan All:
>> When "Greetings" does not exist, I would expect an IO exception. But >> I get nothing. Why? 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.
Roedy Green - 06 Jan 2006 17:03 GMT On Fri, 06 Jan 2006 16:52:47, "Johannes Beekhuizen" <jbeekhui@duinheks.xs4all.nl> wrote, quoted or indirectly quoted someone who said :
>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] );
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Johannes Beekhuizen - 01 Jan 2002 05:00 GMT Hallo Roedy,
Op 06 Jan 06 schreef Roedy Green aan All:
>> When "Greetings" does not exist, I would expect an IO exception. But I >> get nothing. Why? 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.
opalpa@gmail.com - 06 Jan 2006 19:08 GMT 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.
Johannes Beekhuizen - 01 Jan 2002 05:00 GMT Hallo,
Op 06 Jan 06 schreef opalpa@gmail.com 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.
opalpa@gmail.com - 06 Jan 2006 19:08 GMT 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/
Roedy Green - 06 Jan 2006 23:22 GMT On Fri, 06 Jan 2006 19:37:34, "Johannes Beekhuizen" <jbeekhui@duinheks.xs4all.nl> wrote, quoted or indirectly quoted someone who said :
>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
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Johannes Beekhuizen - 01 Jan 2002 05:00 GMT Hallo Roedy,
Op 06 Jan 06 schreef Roedy Green aan All:
>> The idea is that this application will be able to start other >> applications depending on the choice of the user. 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.
Roedy Green - 09 Jan 2006 21:01 GMT On Mon, 09 Jan 2006 21:24:05, "Johannes Beekhuizen" <jbeekhui@duinheks.xs4all.nl> wrote, quoted or indirectly quoted someone who said :
>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.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Thomas Weidenfeller - 10 Jan 2006 08:08 GMT > I hava a question already: I prefer to pass parameters to the spawned > applications by environment variables Which is a bad idea in general, but that is an entirely different story.
> rather than parameters. I have not seen > a way [yet] to do this with this construction. Then you haven't Read The Fine Manual:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.St ring[],%20java.lang.String[])
/Thomas
 Signature The comp.lang.java.gui FAQ: ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|