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 class
ProcessRunner.Result
-
Constructor Summary
Constructors Constructor Description ProcessRunner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
ProcessRunner.Result
exec(byte[] stdin, String... args)
Creates a process with the given arguments, the given byte array is written to stdin immediately.ProcessRunner.Result
exec(byte[] stdin, List<String> args)
Creates a process with the given arguments, the given byte array is written to stdin immediately.ProcessRunner.Result
exec(String... args)
Creates a process with the given arguments.ProcessRunner.Result
exec(List<String> args)
Creates a process with the given arguments.ProcessRunner.Result
shell(String cmd)
Executes the given shell command (usingcmd
on windows andsh
on unix).ProcessRunner.Result
shellWinUnix(String cmdWin, String cmdUnix)
Executes the given shell command (usingcmd
on windows andsh
on unix).
-
-
-
Method Detail
-
shell
public ProcessRunner.Result shell(String cmd) throws IOException, InterruptedException
Executes the given shell command (usingcmd
on windows andsh
on unix).- Throws:
IOException
InterruptedException
-
shellWinUnix
public ProcessRunner.Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, InterruptedException
Executes the given shell command (usingcmd
on windows andsh
on unix).- Throws:
IOException
InterruptedException
-
exec
public ProcessRunner.Result exec(String... args) throws IOException, InterruptedException
Creates a process with the given arguments.- Throws:
IOException
InterruptedException
-
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:
IOException
InterruptedException
-
exec
public ProcessRunner.Result exec(List<String> args) throws IOException, InterruptedException
Creates a process with the given arguments.- Throws:
IOException
InterruptedException
-
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:
IOException
InterruptedException
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
-