yup, that's what it would do alright. I assume you expected something like:
[cabbey@tweedle]~$ ./a.out
a.out was called
[cabbey@tweedle]~$ java runabl
a.out was called
Inside try
java.lang.UNIXProcess@156d6e
[cabbey@tweedle]~$
Right? Wrong.
This is Runtime.exec() functioning as designed. The process is not made as
a system call (method invocation like) but was spawned off as a child
process. Also the stdout, stderr, and stdin of a.out are _not_ attached to
System.out, System.err and System.in of runabl, so the output from a.out
is spooled up waiting for you to read. (assuming it didn't block trying to
write because the pipe was full because you're not listening to it.)
Take a look at the javadocs for Process, particularly the get<>Stream(),
waitFor()*, and getExitCode() methods. Also take a look back through the
recent archive of this list and I think you'll find a discusion of this
topic, including (iirc) some code to create objects which "pipe" the
streams together. -=Chris
*note: Process.waitFor() has some ugly problems (on all platforms)
with never returning your call....
At 05:41 PM 5/12/99 -0400, Yuet Sim Lee wrote:
>I tried the following code:
>
> import java.io.*;
>
> public class runabl {
> public static void main( String[] args )
> {
> try{
> Runtime rt = Runtime.getRuntime();
>
> Process prcs = rt.exec( "a.out" );
> System.out.println("Inside try");
> System.out.println(prcs);
> }
> catch( Exception e ) {
> System.out.println("Catch something");
> System.out.println(e);
> }
> }
> }
>
>However, the output is :
>
> Inside try
> java.lang.UNIXProcess@156d6e
>
>instead of the result from typing "a.out" directly.
>
!NEW!-=> <*> cabbey at home dot net http://members.home.net/cabbey/ <*>
"What can Microsoft do? They certainly can't program around us." - Linus
-----BEGIN GEEK CODE BLOCK----- Version:3.12 http://www.geekcode.com
GCS$/IT/PA$ d(-) s++:+ a-- C+++$ UL++++ UA++$ P++ L++ E- W++ N+ o? K? !P
w---(+)$ O- M-- V-- Y+ PGP+ t--- 5++ X+ R tv b+ DI+++ D G e++ h(+) r@ y?
------END GEEK CODE BLOCK------
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]