Java ProcessBuilder on Ubuntu

Status
Not open for further replies.

Mark Cianciosa

Wise, Aged Ars Veteran
161
I have this server that's only jobs is to run this scientific Fortran code and send the results back to the client. I had an earlier issue where there was so much diagnostic messages and just plain junk output being sent to std out that some buffer, that's internal to java implantation for running external processes, was getting filled causing my external process to goto sleep. Now the my server doesn't care about any this junk so when we were running Solaris, I just piped all that output to /dev/null and that fixed everything. However we recently just had a major server failure and our IT guy switched us over to Ubuntu and now this issue has cropped back up again. The code in question is
Code:
...

ProcessBuilder processbuilder = new ProcessBuilder(execCommand, file.getFullFileName(), "> /dev/null");
processBuilder.directory(file.directory);
processBuilder.redirectErrorStream(true);
Process reconCode = processBuilder.start();
reconCode.waitFor();

...

How can I prevent this process from getting stuck without having to continually read in the output and clear it.
 

Redshift

Ars Scholae Palatinae
1,260
As the code exists above you are redirecting STDOUT to dev null, but STDERR is going to a buffer in the java process.


Code:
processBuilder.redirectErrorStream(true);

I think the above line merges STDERR and STDOUT after they reach the java process. You want to do that before, so they both go to dev null.


Code:
new ProcessBuilder(execCommand, file.getFullFileName(), "> /dev/null 2>&1");
 
Status
Not open for further replies.