spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

How about showing result of command itself in SystemCommandTasklet? [BATCH-2133]

Open spring-projects-issues opened this issue 12 years ago • 1 comments

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

spring-projects-issues avatar Nov 01 '13 20:11 spring-projects-issues

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();
	}

});

spring-projects-issues avatar Nov 09 '18 21:11 spring-projects-issues