Enhanced to pass stdin, stdout and stderr in the Java version.