Executor exec = new DefaultExecutor(); CommandLine cl = new CommandLine("sed"); cl.addArgument("s/hello/goodbye/"); String text = "hello"; ByteArrayInputStream input = new ByteArrayInputStream(text.getBytes("ISO-8859-1")); ByteArrayOutputStream output = new ByteArrayOutputStream(); exec.setStreamHandler(new PumpStreamHandler(output, null, input)); exec.execute(cl); System.out.println("result: " + output.toString("ISO-8859-1"));
CommandLine cmdLine = new CommandLine("mco"); cmdLine.addArgument("shellcmd" ); cmdLine.addArguments( puppetAgents.split(" ") ); cmdLine.addArgument("-t"); cmdLine.addArgument(timeout); // When writing a command with space use double " cmdLine.addArgument("\"\"puppet agent -t\"\"",false);
CommandLine cmdLine = new CommandLine("lftp"); cmdLine.addArgument("-e"); cmdLine.addArgument("set ftp:ssl-protect-data true; put -O /data/upload/ src/test/resources/test-file.txt; bye"); cmdLine.addArgument("-u"); cmdLine.addArgument("username,password"); cmdLine.addArgument("-p"); cmdLine.addArgument("21"); cmdLine.addArgument("192.168.1.100");
CommandLine commandLine = new CommandLine("scp"); commandLine.addArgument("-i", false); commandLine.addArgument(privateKey, false); commandLine.addArgument(currentFile, false); commandLine.addArgument(target + destination, false);
final CommandLine cmdLine = new CommandLine("lftp"); cmdLine.addArgument("-e"); cmdLine.addArgument("set ftp:ssl-protect-data true; put -O /data/upload/ src/test/resources/test-file.txt; bye"); ... executor.execute(cmdLine);
String cmd = "bash"; CommandLine cmdLine = new CommandLine(cmd); cmdLine.addArgument("./src/main/resources/scripts/hub_start.sh"); cmdLine.addArgument(portNumber); executor.execute(cmdLine);
CommandLine commandLine = new CommandLine("/bin/sh"); commandLine.addArgument("-c"); commandLine.addArgument("echo test", false); // false is important to prevent commons-exec from acting stupid executor.execute(commandLine);
CommandLine launchEmul = new CommandLine("Genymotion player path"); launchEmul.addArgument("--vm-name"); launchEmul.addArgument("\""+deviceName+"\""); executor.setExitValue(1); executor.execute(launchEmul, resultHandler);
CommandLine cmdLine = new CommandLine("cmd.exe"); cmdLine.addArgument("/c"); cmdLine.addArgument(".\\phantomjs\\nk\\batchbin\\casperjs.bat"); cmdLine.addArgument(".\\phantomjs\\nk\\batchbin\\dd.js"); cmdLine.addArgument(url); cmdLine.addArgument(">" + rand); DefaultExecutor executor = new DefaultExecutor(); int exitValue = executor.execute(cmdLine);
CommandLine toRet; if ( OS.isFamilyWindows() && exec.toLowerCase( Locale.getDefault() ).endsWith( ".bat" ) ) { toRet = new CommandLine( "cmd" ); toRet.addArgument( "/c" ); toRet.addArgument( exec ); } else { toRet = new CommandLine( exec ); }
private void deleteWithCmd(File toDelete) throws IOException { CommandLine cmdLine = new CommandLine("cmd.exe"); cmdLine.addArgument("/C"); cmdLine.addArgument("del"); cmdLine.addArgument(toDelete.getAbsolutePath()); DefaultExecutor executor = new DefaultExecutor(); int exitValue = executor.execute(cmdLine); }
public static void main(String[] args) throws Exception { execCommons(); } public static void execCommons() throws ExecuteException, IOException { CommandLine cmd = new CommandLine("cmd.exe "); cmd.addArgument("/c"); String command = "mysqldump " + "-u" + "root" + " -P" + "3316" + " -h" + "localhost" + " -A >" + "\"G:\\test.sql \""; cmd.addArgument(command,false); new DefaultExecutor().execute(cmd); }
CommandLine cmdLine = new CommandLine("AcroRd32.exe"); cmdLine.addArgument("/p"); cmdLine.addArgument("/h"); cmdLine.addArgument("${file}"); HashMap map = new HashMap(); map.put("file", new File("invoice.pdf")); commandLine.setSubstitutionMap(map); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); ExecuteWatchdog watchdog = new ExecuteWatchdog(60*1000); Executor executor = new DefaultExecutor(); executor.setExitValue(1); executor.setWatchdog(watchdog); executor.execute(cmdLine, resultHandler); // some time later the result handler callback was invoked so we // can safely request the exit value int exitValue = resultHandler.waitFor()
Map map = new HashMap(); map.put("file", new File("invoice.pdf")); CommandLine cmdLine = new CommandLine("AcroRd32.exe"); cmdLine.addArgument("/p"); cmdLine.addArgument("/h"); cmdLine.addArgument("${file}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine);
CommandLine cmdLine = new CommandLine("AcroRd32.exe"); cmdLine.addArgument("/p"); cmdLine.addArgument("/h"); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); int exitValue = executor.execute(cmdLine);
CommandLine commandLine = new CommandLine("abc.sh"); commandLine.addArgument("param1"); final Executor exec = new DefaultExecutor().execute(commandLine);
CommandLine cmdLine = new CommandLine("ping"); cmdLine.addArgument( host ); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); PumpStreamHandler psh = new PumpStreamHandler( stdout ); DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler( psh ); try { executor.execute( cmdLine ); } catch ( Exception e ) { } System.out.println( stdout.toString() );
commandLine.addArgument(temp.getAbsolutePath());
CommandLine commandLine = new CommandLine( "TestComplete8.bat" ); commandLine.addArgument( ... ); commandLine.addArgument( ... ); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue( 0 ); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); executor.setStreamHandler( new PumpStreamHandler( outputStream, errorStream ) ); try { executor.execute( commandLine ); } catch ( ExecuteException e ) { // TODO: ... } catch ( IOException e ) { // TODO: ... }
static String deviceName = "Google Nexus 5 - 4.4.4 - API 19 - 1080x1920"; public static void main(String[] args) throws InterruptedException, ExecuteException, IOException { DesiredCapabilities capabilities = new DesiredCapabilities(); DefaultExecutor executor = new DefaultExecutor(); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); CommandLine launchEmul = new CommandLine("C:/Program Files/Genymobile/Genymotion/player"); launchEmul.addArgument("--vm-name"); launchEmul.addArgument("\""+deviceName+"\""); executor.setExitValue(1); executor.execute(launchEmul, resultHandler); Thread.sleep(40); capabilities.setCapability("deviceName","Google Nexus 5 - 4.4.4 API 19 - 1080x1920"); capabilities.setCapability("platformVersion", "4.3"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("app","D:/SOFTWARES/Apks/GOA.apk"); driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); System.out.println("SetUp is successful and Appium Driver is launched successfully"); }