List of usage examples for org.apache.commons.exec CommandLine CommandLine
public CommandLine(final CommandLine other)
From source file:ddf.content.plugin.video.VideoThumbnailPlugin.java
private CommandLine getFFmpegInfoCommand(final String videoFilePath) { return new CommandLine(ffmpegPath).addArgument(SUPPRESS_PRINTING_BANNER_FLAG).addArgument(INPUT_FILE_FLAG) .addArgument(videoFilePath, DONT_HANDLE_QUOTING); }
From source file:cc.arduino.contributions.packages.ContributionInstaller.java
private void executeScripts(File folder, Collection<File> postInstallScripts, boolean trusted, boolean trustAll) throws IOException { File script = postInstallScripts.iterator().next(); if (!trusted && !trustAll) { System.err.println(/*from ww w . j ava 2s . c o m*/ I18n.format(tr("Warning: non trusted contribution, skipping script execution ({0})"), script)); return; } if (trustAll) { System.err.println(I18n.format(tr("Warning: forced untrusted script execution ({0})"), script)); } ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); Executor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(stdout, stderr)); executor.setWorkingDirectory(folder); executor.setExitValues(null); int exitValue = executor.execute(new CommandLine(script)); executor.setExitValues(new int[0]); System.out.write(stdout.toByteArray()); System.err.write(stderr.toByteArray()); if (executor.isFailure(exitValue)) { throw new IOException(); } }
From source file:io.selendroid.builder.SelendroidServerBuilder.java
AndroidApp signTestServer(File customSelendroidServer, File outputFileName) throws ShellCommandException, AndroidSdkException { if (outputFileName == null) { throw new IllegalArgumentException("outputFileName parameter is null."); }/*w w w . j a v a 2 s. co m*/ File androidKeyStore = androidDebugKeystore(); if (androidKeyStore.isFile() == false) { // create a new keystore CommandLine commandline = new CommandLine(JavaSdk.keytool()); commandline.addArgument("-genkey", false); commandline.addArgument("-v", false); commandline.addArgument("-keystore", false); commandline.addArgument(androidKeyStore.toString(), false); commandline.addArgument("-storepass", false); commandline.addArgument("android", false); commandline.addArgument("-alias", false); commandline.addArgument("androiddebugkey", false); commandline.addArgument("-keypass", false); commandline.addArgument("android", false); commandline.addArgument("-dname", false); commandline.addArgument("CN=Android Debug,O=Android,C=US", false); commandline.addArgument("-storetype", false); commandline.addArgument("JKS", false); commandline.addArgument("-sigalg", false); commandline.addArgument("MD5withRSA", false); commandline.addArgument("-keyalg", false); commandline.addArgument("RSA", false); commandline.addArgument("-validity", false); commandline.addArgument("9999", false); String output = ShellCommand.exec(commandline, 20000); log.info("A new keystore has been created: " + output); } // Sign the jar CommandLine commandline = new CommandLine(JavaSdk.jarsigner()); commandline.addArgument("-sigalg", false); commandline.addArgument("MD5withRSA", false); commandline.addArgument("-digestalg", false); commandline.addArgument("SHA1", false); commandline.addArgument("-signedjar", false); commandline.addArgument(outputFileName.getAbsolutePath(), false); commandline.addArgument("-storepass", false); commandline.addArgument("android", false); commandline.addArgument("-keystore", false); commandline.addArgument(androidKeyStore.toString(), false); commandline.addArgument(customSelendroidServer.getAbsolutePath(), false); commandline.addArgument("androiddebugkey", false); String output = ShellCommand.exec(commandline, 20000); if (log.isLoggable(Level.INFO)) { log.info("App signing output: " + output); } log.info("The app has been signed: " + outputFileName.getAbsolutePath()); return new DefaultAndroidApp(outputFileName); }
From source file:com.tupilabs.pbs.PBS.java
/** * PBS qsub command.//w w w .j a v a 2 s. c o m * <p> * Equivalent to qsub [param] * * @param input job input file * @return job id */ public static String qsub(String input) { final CommandLine cmdLine = new CommandLine(COMMAND_QSUB); cmdLine.addArgument(input); final OutputStream out = new ByteArrayOutputStream(); final OutputStream err = new ByteArrayOutputStream(); DefaultExecuteResultHandler resultHandler; try { resultHandler = execute(cmdLine, null, out, err); resultHandler.waitFor(DEFAULT_TIMEOUT); } catch (ExecuteException e) { throw new PBSException("Failed to execute qsub command: " + e.getMessage(), e); } catch (IOException e) { throw new PBSException("Failed to execute qsub command: " + e.getMessage(), e); } catch (InterruptedException e) { throw new PBSException("Failed to execute qsub command: " + e.getMessage(), e); } final int exitValue = resultHandler.getExitValue(); LOGGER.info("qsub exit value: " + exitValue); LOGGER.fine("qsub output: " + out.toString()); if (exitValue != 0) throw new PBSException("Failed to submit job script " + input + ". Error output: " + err.toString()); String jobId = out.toString(); return jobId.trim(); }
From source file:com.alibaba.jstorm.yarn.utils.JStormUtils.java
/** * If it is backend, please set resultHandler, such as DefaultExecuteResultHandler If it is frontend, ByteArrayOutputStream.toString get the result * <p/>/*ww w .j a v a2 s . c o m*/ * This function don't care whether the command is successfully or not * * @param command * @param environment * @param workDir * @param resultHandler * @return * @throws IOException */ @Deprecated public static ByteArrayOutputStream launchProcess(String command, final Map environment, final String workDir, ExecuteResultHandler resultHandler) throws IOException { String[] cmdlist = command.split(" "); CommandLine cmd = new CommandLine(cmdlist[0]); for (String cmdItem : cmdlist) { if (StringUtils.isBlank(cmdItem) == false) { cmd.addArgument(cmdItem); } } DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); if (StringUtils.isBlank(workDir) == false) { executor.setWorkingDirectory(new File(workDir)); } ByteArrayOutputStream out = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(out, out); if (streamHandler != null) { executor.setStreamHandler(streamHandler); } try { if (resultHandler == null) { executor.execute(cmd, environment); } else { executor.execute(cmd, environment, resultHandler); } } catch (ExecuteException e) { // @@@@ // failed to run command } return out; }
From source file:io.selendroid.standalone.android.impl.DefaultAndroidEmulator.java
@Override public void start(Locale locale, int emulatorPort, Map<String, Object> options) throws AndroidDeviceException { if (isEmulatorStarted()) { throw new SelendroidException("Error - Android emulator is already started " + this); }// ww w .ja va2s . c om Long timeout = null; String emulatorOptions = null; String display = null; if (options != null) { if (options.containsKey(TIMEOUT_OPTION)) { timeout = (Long) options.get(TIMEOUT_OPTION); } if (options.containsKey(DISPLAY_OPTION)) { display = (String) options.get(DISPLAY_OPTION); } if (options.containsKey(EMULATOR_OPTIONS)) { emulatorOptions = (String) options.get(EMULATOR_OPTIONS); } } if (display != null) { log.info("Using display " + display + " for running the emulator"); } if (timeout == null) { timeout = 120000L; } log.info("Using timeout of '" + timeout / 1000 + "' seconds to start the emulator."); this.locale = locale; CommandLine cmd = new CommandLine(AndroidSdk.emulator()); cmd.addArgument("-no-snapshot-save", false); cmd.addArgument("-avd", false); cmd.addArgument(avdName, false); cmd.addArgument("-port", false); cmd.addArgument(String.valueOf(emulatorPort), false); if (locale != null) { cmd.addArgument("-prop", false); cmd.addArgument("persist.sys.language=" + locale.getLanguage(), false); cmd.addArgument("-prop", false); cmd.addArgument("persist.sys.country=" + locale.getCountry(), false); } if (emulatorOptions != null && !emulatorOptions.isEmpty()) { cmd.addArguments(emulatorOptions.split(" "), false); } long start = System.currentTimeMillis(); long timeoutEnd = start + timeout; try { ShellCommand.execAsync(display, cmd); } catch (ShellCommandException e) { throw new SelendroidException("unable to start the emulator: " + this); } setSerial(emulatorPort); Boolean adbKillServerAttempted = false; // Without this one seconds, the call to "isDeviceReady" is // too quickly sent while the emulator is still starting and // not ready to receive any commands. Because of this the // while loops failed and sometimes hung in isDeviceReady function. try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } while (!isDeviceReady()) { if (!adbKillServerAttempted && System.currentTimeMillis() - start > 10000) { CommandLine adbDevicesCmd = new CommandLine(AndroidSdk.adb()); adbDevicesCmd.addArgument("devices", false); String devices = ""; try { devices = ShellCommand.exec(adbDevicesCmd, 20000); } catch (ShellCommandException e) { // pass } if (!devices.contains(String.valueOf(emulatorPort))) { CommandLine resetAdb = new CommandLine(AndroidSdk.adb()); resetAdb.addArgument("kill-server", false); try { ShellCommand.exec(resetAdb, 20000); } catch (ShellCommandException e) { throw new SelendroidException("unable to kill the adb server"); } } adbKillServerAttempted = true; } if (timeoutEnd >= System.currentTimeMillis()) { try { Thread.sleep(2000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } else { throw new AndroidDeviceException("The emulator with avd '" + getAvdName() + "' was not started after " + (System.currentTimeMillis() - start) / 1000 + " seconds."); } } log.info("Emulator start took: " + (System.currentTimeMillis() - start) / 1000 + " seconds"); log.info("Please have in mind, starting an emulator takes usually about 45 seconds."); unlockScreen(); waitForLauncherToComplete(); // we observed that emulators can sometimes not be 'fully loaded' // if we click on the All Apps button and wait for it to load it is more likely to be in a // usable state. allAppsGridView(); waitForLauncherToComplete(); setWasStartedBySelendroid(true); }
From source file:Logi.GSeries.Service.LogiGSKService.java
public void showSystemTray() { if ((systemTray != null) && !systemTrayVisible) { systemTray.setEnabled(true);//from w w w . j av a 2 s . c o m systemTrayVisible = true; return; } try { systemTray = SystemTray.getNative(); } catch (Exception ex) { System.out.println(ex.getMessage()); Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex); } if (systemTray != null) { try { systemTray.setImage(GSK_Icon); } catch (Exception e) { System.err.println("Problem setting system tray icon."); } systemTrayVisible = true; callbackOpen = new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final MenuItem entry = (MenuItem) e.getSource(); try { CommandLine commandLine = new CommandLine("java"); commandLine.addArgument("-jar"); String jarPath = new URI( LogiGSKService.class.getProtectionDomain().getCodeSource().getLocation().getPath()) .getPath(); commandLine.addArgument(jarPath, false); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); executor.execute(commandLine, new DefaultExecuteResultHandler()); } catch (URISyntaxException ex) { Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex); } } }; callbackAbout = new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final MenuItem entry = (MenuItem) e.getSource(); JOptionPane.showMessageDialog(null, "<HTML>LogiGSK V1.0</HTML>", "LogiGSK", JOptionPane.INFORMATION_MESSAGE); } }; Menu mainMenu = systemTray.getMenu(); MenuItem openEntry = new MenuItem("Open", new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final MenuItem entry = (MenuItem) e.getSource(); entry.setCallback(callbackOpen); try { CommandLine commandLine = new CommandLine("java"); commandLine.addArgument("-jar"); String jarPath = new URI( LogiGSKService.class.getProtectionDomain().getCodeSource().getLocation().getPath()) .getPath(); commandLine.addArgument(jarPath, false); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); executor.execute(commandLine, new DefaultExecuteResultHandler()); } catch (URISyntaxException ex) { Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex); } } }); openEntry.setShortcut('O'); mainMenu.add(openEntry); mainMenu.add(new Separator()); MenuItem aboutEntry = new MenuItem("About", new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final MenuItem entry = (MenuItem) e.getSource(); JOptionPane.showMessageDialog(null, "<HTML>LogiGSK V1.0</HTML>", "LogiGSK", JOptionPane.INFORMATION_MESSAGE); entry.setCallback(callbackAbout); } }); openEntry.setShortcut('A'); mainMenu.add(aboutEntry); /*} else { System.err.println("System tray is null!"); }*/ } }
From source file:io.selendroid.standalone.builder.SelendroidServerBuilder.java
AndroidApp signTestServer(File customSelendroidServer, File outputFileName) throws ShellCommandException, AndroidSdkException { if (outputFileName == null) { throw new IllegalArgumentException("outputFileName parameter is null."); }/*from ww w. java2 s.com*/ File androidKeyStore = androidDebugKeystore(); if (!androidKeyStore.isFile()) { // create a new keystore CommandLine commandline = new CommandLine(JavaSdk.keytool()); commandline.addArgument("-genkey", false); commandline.addArgument("-v", false); commandline.addArgument("-keystore", false); commandline.addArgument(androidKeyStore.toString(), false); commandline.addArgument("-storepass", false); commandline.addArgument(storepass, false); commandline.addArgument("-alias", false); commandline.addArgument(alias, false); commandline.addArgument("-keypass", false); commandline.addArgument(storepass, false); commandline.addArgument("-dname", false); commandline.addArgument("CN=Android Debug,O=Android,C=US", false); commandline.addArgument("-storetype", false); commandline.addArgument("JKS", false); commandline.addArgument("-sigalg", false); commandline.addArgument("MD5withRSA", false); commandline.addArgument("-keyalg", false); commandline.addArgument("RSA", false); commandline.addArgument("-validity", false); commandline.addArgument("9999", false); String output = ShellCommand.exec(commandline, 20000); log.info("A new keystore has been created: " + output); } // Sign the jar CommandLine commandline = new CommandLine(JavaSdk.jarsigner()); commandline.addArgument("-sigalg", false); commandline.addArgument(getSigAlg(), false); commandline.addArgument("-digestalg", false); commandline.addArgument("SHA1", false); commandline.addArgument("-signedjar", false); commandline.addArgument(outputFileName.getAbsolutePath(), false); commandline.addArgument("-storepass", false); commandline.addArgument(storepass, false); commandline.addArgument("-keystore", false); commandline.addArgument(androidKeyStore.toString(), false); commandline.addArgument(customSelendroidServer.getAbsolutePath(), false); commandline.addArgument(alias, false); String output = ShellCommand.exec(commandline, 20000); if (log.isLoggable(Level.INFO)) { log.info("App signing output: " + output); } log.info("The app has been signed: " + outputFileName.getAbsolutePath()); return new DefaultAndroidApp(outputFileName); }
From source file:com.netflix.genie.core.jobs.workflow.impl.JobKickoffTask.java
/** * Method to change the ownership of a directory. * * @param dir The directory to change the ownership of. * @param user Userid of the user.//w w w . jav a2s.com * @throws GenieException If there is a problem. */ protected void changeOwnershipOfDirectory(final String dir, final String user) throws GenieException { final CommandLine commandLine = new CommandLine("sudo").addArgument("chown").addArgument("-R") .addArgument(user).addArgument(dir); try { this.executor.execute(commandLine); } catch (IOException ioexception) { throw new GenieServerException("Could not change ownership with exception " + ioexception); } }
From source file:com.netflix.genie.web.jobs.workflow.impl.JobKickoffTask.java
/** * Method to change the ownership of a directory. * * @param dir The directory to change the ownership of. * @param user Userid of the user.//from w w w. j a v a 2s . c o m * @throws GenieException If there is a problem. */ protected void changeOwnershipOfDirectory(final String dir, final String user) throws GenieException { final CommandLine commandLine = new CommandLine("sudo").addArgument("chown").addArgument("-R") .addArgument(user).addArgument(dir); try { this.executor.execute(commandLine); } catch (IOException ioexception) { throw new GenieServerException("Could not change ownership", ioexception); } }