devjta / java-registry

Automatically exported from code.google.com/p/java-registry
1 stars 4 forks source link

Writing to temporary files sometimes fails #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It seems that using some "version" of Windows 8 the redirect of command 
executions to temporary files produces empty files (I also tried to increase 
the value of WAIT_FOR_FILE). I find it difficult to discover which "version" 
causes the problem. Have you ever noticed that problem?

Wouldn't it be better not to write to the disk when you can work with in-memory 
data?

I'd suggest to replace all the code

File f = File.createTempFile("regorexp", ".jta");
Runtime.getRuntime().exec(command).waitFor();       
_waitForFile(f);
br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));

with 

Process proc = Runtime.getRuntime().exec(command);
int exitCode = proc.waitFor();
br = new BufferedReader(new InputStreamReader(proc.getInputStream()));

Do you think there could be any side effects?

Thanks,
   Giacomo Boccardo.

Original issue reported on code.google.com by gboccard on 7 May 2013 at 12:49

GoogleCodeExporter commented 9 years ago
The problem is the Process/Runtime classes itself. 
If the buffer gets to big the Runtime/Process call will result in a 
freez/deadlock/hung.

At least that bug/miss-feature was in old java-version present:

http://www.coderanch.com/t/371081/java/java/Runtime-exec-haning-Buffer
http://dhruba.name/2012/10/16/java-pitfall-how-to-prevent-runtime-getruntime-exe
c-from-hanging/

I will try to fix the other bug and add it to Maven. After this i can make a 
test-version where i read out the streams directly from the process class.

Original comment by bEha...@gmail.com on 24 Jul 2013 at 4:59