cmd = new CommandLine();
cmd = new CommandLine();
@Test public void testGetOptions() { CommandLine cmd = new CommandLine(); assertNotNull(cmd.getOptions()); assertEquals(0, cmd.getOptions().length); cmd.addOption(new Option("a", null)); cmd.addOption(new Option("b", null)); cmd.addOption(new Option("c", null)); assertEquals(3, cmd.getOptions().length); }
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"));
if (isUnix()) { commandline = new CommandLine("/usr/local/bin/node"); commandline.addArguments(new String[] { "/usr/local/bin/bower","--allow-root"}, false); }
cmdLine = new CommandLine("cmd.exe"); cmdLine.addArgument("/c"); cmdLine.addArgument(new StringBuilder().append("\"").append(command).append("\"").toString()); logger.info("Command win line: cmd.exe /c \""+command + "\"");
Executor exec = new DefaultExecutor(); exec.setWorkingDirectory(new File("C:\\My\\Dir\\")); CommandLine cl = new CommandLine("mybatch.bat"); int exitvalue = exec.execute(cl);
Executor exec = new DefaultExecutor(); exec.setWorkingDirectory(file); CommandLine cl = new CommandLine("./runCommand.sh"); int exitvalue = exec.execute(cl); if (exitvalue == 0) System.out.println("./runCommand.sh succeeded....");
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 ); }
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);
CommandLine launchEmul = new CommandLine("Genymotion player path"); launchEmul.addArgument("--vm-name"); launchEmul.addArgument("\""+deviceName+"\""); executor.setExitValue(1); executor.execute(launchEmul, resultHandler);
CommandLine command = new CommandLine("/bin/sh"); command.addArguments(new String[] { "-c", "echo 'test'" },false); new DefaultExecutor().execute(command);
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() );
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 commandLine = new CommandLine("scp"); commandLine.addArgument("-i", false); commandLine.addArgument(privateKey, false); commandLine.addArgument(currentFile, false); commandLine.addArgument(target + destination, false);
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("AcroRd32.exe"); cmdLine.addArgument("/p"); cmdLine.addArgument("/h"); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); int exitValue = executor.execute(cmdLine);
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 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);