By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

runtime.exec Process

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
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.