471,338 Members | 915 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

runtime.exec Process

When I was using Runtime.exec(String cmd) to run a unix utility (join), and
try to
get its standard output by using Process.getOutputStream(), it blocks
forever. I tried
it using Java 1.4 and the results are the same on SunOS 5.8, Redhat8.0,
cygwin.

I read relevant articles and find the reason is that the output of the
process exceeds the
buffer allocated for that process. So can I adjust the buffer size (on any
of the platforms)?

also, is there a way to get the outputstream of the process and save it to a
intermediate file?
(just the same as "join file1 file2 > output_file", but apparently this
does not work in the
context of "Runtime.exec(...)")

your help will be greatly appreciated!

Henry
Jul 17 '05 #1
2 10893
"uwnewsgroup" <uw*********@hotmail.com> wrote in message
news:c5**********@rumours.uwaterloo.ca...
When I was using Runtime.exec(String cmd) to run a unix utility (join), and try to
get its standard output by using Process.getOutputStream(), it blocks
forever. I tried
it using Java 1.4 and the results are the same on SunOS 5.8, Redhat8.0,
cygwin.

I read relevant articles and find the reason is that the output of the
process exceeds the
buffer allocated for that process. So can I adjust the buffer size (on any of the platforms)?

also, is there a way to get the outputstream of the process and save it to a intermediate file?
(just the same as "join file1 file2 > output_file", but apparently this
does not work in the
context of "Runtime.exec(...)")

your help will be greatly appreciated!

Henry

Some coworkers of mine have been experimenting with Runtime.exec and had the
same problem of the process apparently stalling (using Windows XP). They
said something about the error stream buffer filling up and having to call
getErrorStream and close it to allow the process to finish.
Jul 17 '05 #2
uwnewsgroup wrote:
When I was using Runtime.exec(String cmd) to run a unix utility (join), and
try to
get its standard output by using Process.getOutputStream(), it blocks
forever. I tried
it using Java 1.4 and the results are the same on SunOS 5.8, Redhat8.0,
cygwin.

I read relevant articles and find the reason is that the output of the
process exceeds the
buffer allocated for that process. So can I adjust the buffer size (on any
of the platforms)?

also, is there a way to get the outputstream of the process and save it to a
intermediate file?
(just the same as "join file1 file2 > output_file", but apparently this
does not work in the
context of "Runtime.exec(...)")


Redirection, piping, etc. is a function of the shell (e.g. bash, csh,
DOS, etc.). If you wish to use it from Runtime.exec() you must execute
it. For example:

Runtime.getRuntime().exec("sh -c \"join file1 file2 > file3\"");

or

Runtime.getRuntime().exec(new Strng[] {"sh", "-c",
"join file1 file2 > file3"});
If your process is hitting a buffer limit, simply read from standard out
or standard error until the process finishes.

Ray

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hal Vaughan | last post: by
1 post views Thread by Hal Vaughan | last post: by
5 posts views Thread by Ayesha Ahsan | last post: by
2 posts views Thread by jerry chapman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.