Write script output to temporary log file
This commit is contained in:
parent
8cc6f7ae0e
commit
5fa939ae65
|
@ -1,5 +1,7 @@
|
||||||
package ctbrec.recorder.postprocessing;
|
package ctbrec.recorder.postprocessing;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -35,12 +37,16 @@ public class Script extends AbstractPlaceholderAwarePostProcessor {
|
||||||
LOG.debug("Running {}", Arrays.toString(args));
|
LOG.debug("Running {}", Arrays.toString(args));
|
||||||
}
|
}
|
||||||
Process process = rt.exec(args, OS.getEnvironment());
|
Process process = rt.exec(args, OS.getEnvironment());
|
||||||
startLogging(process);
|
File logFile = File.createTempFile("execute_script_" + rec.getId() + "_", ".log");
|
||||||
|
logFile.deleteOnExit();
|
||||||
|
try (FileOutputStream logStream = new FileOutputStream(logFile)) {
|
||||||
|
startLogging(process, logStream);
|
||||||
int exitCode = process.waitFor();
|
int exitCode = process.waitFor();
|
||||||
LOG.debug("Process finished with exit code {}", exitCode);
|
LOG.debug("Process finished with exit code {}", exitCode);
|
||||||
if (exitCode != 0) {
|
if (exitCode != 0) {
|
||||||
throw new ProcessExitedUncleanException("Script finished with exit code " + exitCode);
|
throw new ProcessExitedUncleanException("Script finished with exit code " + exitCode);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,13 +60,12 @@ public class Script extends AbstractPlaceholderAwarePostProcessor {
|
||||||
return cmdline;
|
return cmdline;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startLogging(Process process) {
|
private void startLogging(Process process, FileOutputStream logStream) {
|
||||||
// TODO maybe write these to a separate log file, e.g. recname.ts.script.log
|
Thread std = new Thread(new StreamRedirectThread(process.getInputStream(), logStream));
|
||||||
Thread std = new Thread(new StreamRedirectThread(process.getInputStream(), System.out));
|
|
||||||
std.setName("Process stdout pipe");
|
std.setName("Process stdout pipe");
|
||||||
std.setDaemon(true);
|
std.setDaemon(true);
|
||||||
std.start();
|
std.start();
|
||||||
Thread err = new Thread(new StreamRedirectThread(process.getErrorStream(), System.err));
|
Thread err = new Thread(new StreamRedirectThread(process.getErrorStream(), logStream));
|
||||||
err.setName("Process stderr pipe");
|
err.setName("Process stderr pipe");
|
||||||
err.setDaemon(true);
|
err.setDaemon(true);
|
||||||
err.start();
|
err.start();
|
||||||
|
|
Loading…
Reference in New Issue