in command.line/java/jetbrains/buildServer/core/runtime/RuntimeUtil.java [32:57]
public static void execAndWait(final String command, final File dir, final IProgressMonitor monitor) throws IOException {
monitor.status(new ProgressStatus(ProgressStatus.OK, String.format("Executing command: \"%s\" in %s", command, dir)));
final String[] envp = makeEnv(System.getenv());
Process process = Runtime.getRuntime().exec(makeArguments(command), envp, dir);
final StringBuffer errBuffer = new StringBuffer();
final StringBuffer outBuffer = new StringBuffer();
final Thread errReader = pipe(process.getErrorStream(), monitor, true);
final Thread outReader = pipe(process.getInputStream(), monitor, false);
try {
int result = process.waitFor();
// wait for readers to finish...
errReader.join();
outReader.join();
process.getErrorStream().close();
process.getInputStream().close();
monitor.status(new ProgressStatus(ProgressStatus.OK, String.format("stdout:\n%s", outBuffer.toString())));
if (result != 0 || (errBuffer != null && errBuffer.length() > 0)) {
monitor.status(new ProgressStatus(ProgressStatus.OK, String.format("stderr:\n%s", errBuffer.toString())));
monitor.status(new ProgressStatus(ProgressStatus.OK, String.format("env: %s", Arrays.toString(envp))));
throw new IOException(String.format("%s: command: {\"%s\" in: \"%s\"}, retcode='%d'", errBuffer.toString().trim(), command.trim(), dir.getAbsolutePath(), result));
}
} catch (InterruptedException e) {
throw new IOException(e.getMessage());
}
}