spring-batch
spring-batch copied to clipboard
How about showing result of command itself in SystemCommandTasklet? [BATCH-2133]
Joohee Kang opened BATCH-2133 and commented
When I try to use SystemCommandTasklet, it doesn't show output messages of command it self. (ex. java -version) I think it's efficient to show messages of result including errors if necessary. And it helps developer do test functions. How about add it?
Affects: 2.2.2
Issue Links:
- BATCH-2329 Add log management to SystemCommandTasklet
Mahmoud Ben Hassine commented
This should be possible thanks to the java.lang.ProcessBuilder#inheritIO API. Here is a quick sample:
class Scratch {
public static void main(String[] args) throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("javac", "-version");
processBuilder.inheritIO();
Process process = processBuilder.start();
process.waitFor();
}
}
If the SystemCommandTasklet uses this API instead of Runtime.getRuntime().exec, we can achieve the requested feature by adding an option inheritIO to the SystemCommandTasklet, something like:
FutureTask<Integer> systemCommandTask = new FutureTask<>(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder()
.command(command)
.directory(workingDirectory);
if (inheritIO) {
processBuilder.inheritIO();
}
Process process = processBuilder.start();
return process.waitFor();
}
});