So, I am trying to execute a shell script that produces a lot of output (in 100's MB) from a Java file. It freezes the process and never ends.
However, in a shell script, if I redirect the script output to some log file or / dev / null, the Java file is executed and terminated in jiffy.
Is it because of the amount of data that a Java program never completes? If so, is there any documentation as such? or is there a limit on the amount of data (documented)?
Here is how you can simulate this scenario.
The Java file will look like this:
import java.io.InputStream; public class LotOfOutput { public static void main(String[] args) { String cmd = "sh a-script-which-outputs-huuggee-data.sh"; try { ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd); pb.redirectErrorStream(true); Process shell = pb.start(); InputStream shellIn = shell.getInputStream(); int shellExitStatus = shell.waitFor(); System.out.println(shellExitStatus); shellIn.close(); } catch (Exception ignoreMe) { } } }
script 'a- script -which-outputs-huuggee-data.sh' might look like this:
#!/bin/sh
Free beer for the right answer. :)
java shell
pavanlimo
source share