Question about Runtime.getRuntime().exec()

Hi,

I run the following problem on Linux with java 1.4.2_11.

"/home/yinglcs/myprogram" is a native program which generate a file locally.

however, the files does not generate until I exit my Java Program (which calls "/home/yinglcs/myprogram" using getRuntime().exec()).

can someone please tell me why? How can I change that, I don't want the file io of my native program until AFTER my java program exists.

String envp[] = new String[4];

envp[0] = "LD_LIBRARY_PATH=" + LD_LIBRARY_PATH;

envp[3] = "DISPLAY=:0";

envp[2] = "HOME=" + HOME_DIRECTORY;

envp[1] = "SHELL=/bin/bash";

String cmd = "/home/yinglcs/myprogram";

System.err.println ("cmd" + cmd);

Process p = Runtime.getRuntime().exec( cmd, envp );

Thank you for any help.

[821 byte] By [yinglcs2a] at [2007-10-2 18:26:43]
# 1
I suspect you need to read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
sabre150a at 2007-7-13 19:47:50 > top of Java-index,Java Essentials,Java Programming...
# 2
I read that, but that does not help my problem. thanks for any idea.
yinglcs2a at 2007-7-13 19:47:50 > top of Java-index,Java Essentials,Java Programming...
# 3

exec() starts the other process and returns. So the other process is running at the same time (subject to CPU sharing) that your Java app is. If you're expecting that the other process already wrote its output by the time exec() returns, you're mistaken. Maybe you need to wait for the other app to end, by invoking p.waitFor().

Or maybe the other process input/output streams are blocked because it's waiting for your spawning process to supply input or consume the output, which is mostly about what the link given talks about.

warnerjaa at 2007-7-13 19:47:50 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks. but If i do this instead, it works.Anyone have any idea why?Runtime.getRunTime().exec('xterm -e /home/yinglcs/myprogram') ;of Runtime.getRunTime().exec('/home/yinglcs/myprogram') ;
yinglcs2a at 2007-7-13 19:47:50 > top of Java-index,Java Essentials,Java Programming...
# 5
My guess is that by opening it in an xterm, you're avoiding the blocked i/o problem, which actually was covered in the reference sabre150 gave you and which warnerja also pointed out.Did you actually try dealing with the i/o?
paulcwa at 2007-7-13 19:47:50 > top of Java-index,Java Essentials,Java Programming...