Permalink
Browse files

[FIXED HUDSON-8420] With IBM JDK for example, it seems like there's no

differentiation between Process InputStream&ErrorStream :-(. This
means that closing errorStream will actually close every streams.
  • Loading branch information...
1 parent 56501b4 commit 3c5c2c5cc335c1bb19c4e92bd4f75a715468dd33 @batmat batmat committed with kohsuke Feb 12, 2011
Showing with 12 additions and 6 deletions.
  1. +12 −6 core/src/main/java/hudson/Proc.java
@@ -190,20 +190,26 @@ private LocalProc( String name, ProcessBuilder procBuilder, InputStream in, Outp
this.cookie = EnvVars.createCookie();
procBuilder.environment().putAll(cookie);
this.proc = procBuilder.start();
- copier = new StreamCopyThread(name+": stdout copier", proc.getInputStream(), out);
+ InputStream procInputStream = proc.getInputStream();
+ copier = new StreamCopyThread(name+": stdout copier", procInputStream, out);
copier.start();
if(in!=null)
new StdinCopyThread(name+": stdin copier",in,proc.getOutputStream()).start();
else
proc.getOutputStream().close();
+ InputStream procErrorStream = proc.getErrorStream();
if(err!=null) {
- copier2 = new StreamCopyThread(name+": stderr copier", proc.getErrorStream(), err);
+ copier2 = new StreamCopyThread(name+": stderr copier", procErrorStream, err);
copier2.start();
} else {
- // while this is not discussed in javadoc, even with ProcessBuilder.redirectErrorStream(true),
- // Process.getErrorStream() still returns a distinct reader end of a pipe that needs to be closed.
- // this is according to the source code of JVM
- proc.getErrorStream().close();
+ // On IBM JDK5, returned input and error streams might be the same.
+ // So, in this case, closing one isn't a good idea since it will close both.
+ if (procErrorStream!=procInputStream) {
+ // while this is not discussed in javadoc, even with ProcessBuilder.redirectErrorStream(true),
+ // Process.getErrorStream() still returns a distinct reader end of a pipe that needs to be closed.
+ // this is according to the source code of HotSpot JVM
+ procErrorStream.close();
+ }
copier2 = null;
}
}

0 comments on commit 3c5c2c5

Please sign in to comment.