Class CommandlineExecutor
- java.lang.Object
-
- org.apache.maven.surefire.extensions.util.CommandlineExecutor
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class CommandlineExecutor extends java.lang.Object implements java.io.Closeable
Programming model with this class:try ( CommandlineExecutor exec = new CommandlineExecutor( cli, endOfStreamsCountdown ); CommandlineStreams streams = exec.execute() ) { // register exec in the shutdown hook to destroy pending process // register streams in the shutdown hook to close all three streams ReadableByteChannel stdOut = streams.getStdOutChannel(); ReadableByteChannel stdErr = streams.getStdErrChannel(); WritableByteChannel stdIn = streams.getStdInChannel(); // lineConsumerThread = new LineConsumerThread( ..., stdErr, ..., endOfStreamsCountdown ); // lineConsumerThread.start(); // stdIn.write( ... ); int exitCode = exec.awaitExit(); // process exitCode } catch ( InterruptedException e ) { lineConsumerThread.disable(); } catch ( CommandLineException e ) { // handle the exceptions }
-
-
Constructor Summary
Constructors Constructor Description CommandlineExecutor(org.apache.maven.shared.utils.cli.Commandline cli, CountdownCloseable endOfStreamsCountdown)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
awaitExit()
void
close()
CommandlineStreams
execute()
-
-
-
Constructor Detail
-
CommandlineExecutor
public CommandlineExecutor(org.apache.maven.shared.utils.cli.Commandline cli, CountdownCloseable endOfStreamsCountdown)
-
-
Method Detail
-
execute
public CommandlineStreams execute() throws org.apache.maven.shared.utils.cli.CommandLineException
- Throws:
org.apache.maven.shared.utils.cli.CommandLineException
-
awaitExit
public int awaitExit() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-