package mhashim6.commander;

import mhashim6.commander.exceptions.UnrecognisedCmdException;
import mhashim6.commander.main.Appender;
import mhashim6.commander.main.Command;
import mhashim6.commander.main.CommandBuilder;
import mhashim6.commander.main.CommandExecutor;
import mhashim6.commander.main.ExecutionOutputPrinter;
import mhashim6.commander.main.ExecutionReport;
import mhashim6.commander.main.ProcessMonitor;

/**
 * @author mhashim6
 */
public class Sample {

	public static void main(String[] args) {

		Command cmd = new CommandBuilder("adb devices").withOptions("-l").build();
		ExecutionOutputPrinter eop = new ExecutionOutputPrinter(new Appender() {

			@Override
			public void appendStdText(String text) {
				// your code to show std output lines.
			}

			@Override
			public void appendErrText(String text) {
				// your code to show error lines.
			}
		});

		try {
			ProcessMonitor pMonitor = CommandExecutor.execute(cmd, eop); //execute the command, redirect the output to eop.
			ExecutionReport report = pMonitor.getExecutionReport(); //blocks until the process finishes.

			pMonitor.abort();
			String commandLine = cmd.toString();
			int exitCode = report.exitValue();

			System.out.printf("command line: %s\nexecution finished with exit code: %d\n\n", commandLine, exitCode);
		}
		catch (UnrecognisedCmdException e) {
			System.err.println(e);
		}
	}
}

@@ -546,37 +546,35 @@
 er(%22
-adb devices%22).withOptions(%22-l
+ping%22).withArgs(%22google.com
 %22).b
@@ -1091,31 +1091,26 @@
 shes
-.%0A%0A%09%09%09pMonitor.
+ or gets 
 abort
-();
+ed.%0A
 %0A%09%09%09

update sample