Package com.diffplug.spotless
Class ProcessRunner
- java.lang.Object
-
- com.diffplug.spotless.ProcessRunner
-
- All Implemented Interfaces:
AutoCloseable
public class ProcessRunner extends Object implements AutoCloseable
Shelling out to a process is harder than it ought to be in Java. If you don't read stdout and stderr on their own threads, you risk deadlock on a clogged buffer. ProcessRunner allocates two threads specifically for the purpose of flushing stdout and stderr to buffers. These threads will remain alive until the ProcessRunner is closed, so it is especially useful for repeated calls to an external process.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classProcessRunner.Result
-
Constructor Summary
Constructors Constructor Description ProcessRunner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ProcessRunner.Resultexec(byte[] stdin, String... args)Creates a process with the given arguments, the given byte array is written to stdin immediately.ProcessRunner.Resultexec(byte[] stdin, List<String> args)Creates a process with the given arguments, the given byte array is written to stdin immediately.ProcessRunner.Resultexec(String... args)Creates a process with the given arguments.ProcessRunner.Resultexec(List<String> args)Creates a process with the given arguments.ProcessRunner.Resultshell(String cmd)Executes the given shell command (usingcmdon windows andshon unix).ProcessRunner.ResultshellWinUnix(String cmdWin, String cmdUnix)Executes the given shell command (usingcmdon windows andshon unix).
-
-
-
Method Detail
-
shell
public ProcessRunner.Result shell(String cmd) throws IOException, InterruptedException
Executes the given shell command (usingcmdon windows andshon unix).- Throws:
IOExceptionInterruptedException
-
shellWinUnix
public ProcessRunner.Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, InterruptedException
Executes the given shell command (usingcmdon windows andshon unix).- Throws:
IOExceptionInterruptedException
-
exec
public ProcessRunner.Result exec(String... args) throws IOException, InterruptedException
Creates a process with the given arguments.- Throws:
IOExceptionInterruptedException
-
exec
public ProcessRunner.Result exec(byte[] stdin, String... args) throws IOException, InterruptedException
Creates a process with the given arguments, the given byte array is written to stdin immediately.- Throws:
IOExceptionInterruptedException
-
exec
public ProcessRunner.Result exec(List<String> args) throws IOException, InterruptedException
Creates a process with the given arguments.- Throws:
IOExceptionInterruptedException
-
exec
public ProcessRunner.Result exec(byte[] stdin, List<String> args) throws IOException, InterruptedException
Creates a process with the given arguments, the given byte array is written to stdin immediately.- Throws:
IOExceptionInterruptedException
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
-