List of usage examples for org.apache.commons.exec CommandLine parse
public static CommandLine parse(final String line)
From source file:com.wipro.ats.bdre.tdimport.QueuedFileUploader.java
private static void importFile(FileCopyInfo fileCopying) throws IOException { try {// ww w . j a v a 2s.co m String sCommandString; String subProcessId = fileCopying.getSubProcessId(); GetProcess getProcess = new GetProcess(); String params[] = { "-p", subProcessId }; ProcessInfo processInfo = getProcess.getParentInfoFromSubProcess(params); String monDirName = new GetProperties().getProperties(subProcessId, "td-load") .getProperty("monitored-dir-name"); String targetDirPath = "tdload/" + processInfo.getBusDomainId() + "/" + processInfo.getProcessTypeId() + "/" + processInfo.getProcessId(); String absoluteFilePath = "tdload/" + processInfo.getBusDomainId() + "/" + processInfo.getProcessTypeId() + "/" + processInfo.getProcessId() + "/" + fileCopying.getFileName(); String command = "sh " + MDConfig.getProperty("execute.script-path") + "/file-loader-remote.sh" + " " + absoluteFilePath + " " + fileCopying.getTdDB() + " " + fileCopying.getTdTable() + " " + fileCopying.getTdUserName() + " " + fileCopying.getTdPassword() + " " + fileCopying.getTdTpdid() + " " + fileCopying.getTdDelimiter() + " " + targetDirPath + " " + monDirName + " " + fileCopying.getFileName(); sCommandString = command; CommandLine oCmdLine = CommandLine.parse(sCommandString); LOGGER.debug("executing command :" + command); DefaultExecutor oDefaultExecutor = new DefaultExecutor(); //oDefaultExecutor.setExitValue(0); oDefaultExecutor.execute(oCmdLine); } catch (Exception e) { FileMonitor.addToQueue(fileCopying.getFileName(), fileCopying); LOGGER.error("Error in importing file into TD. Requeuing file " + fileCopying.getFileName(), e); throw new IOException(e); } }
From source file:com.zxy.commons.exec.CmdExecutor.java
/** * //from w w w. ja v a2 s .c o m * * @param workHome workHome * @param command command * @throws InterruptedException InterruptedException * @throws IOException IOException */ public static void execAsyc(String workHome, String command) throws InterruptedException, IOException { CommandLine cmdLine = CommandLine.parse(PRE_CMD + command); Executor executor = new DefaultExecutor(); executor.setWorkingDirectory(new File(workHome)); executor.setStreamHandler(new PumpStreamHandler(new LogOutputStream() { @Override protected void processLine(String line, int level) { LOGGER.debug(line); } }, new LogOutputStream() { @Override protected void processLine(String line, int level) { LOGGER.debug(line); } })); ExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); executor.execute(cmdLine, EnvironmentUtils.getProcEnvironment(), resultHandler); // resultHandler.waitFor(); }
From source file:com.blackducksoftware.tools.scmconnector.integrations.serena.SerenaConnector.java
@Override public int sync() { CommandLine command = CommandLine.parse(executable); int exitStatus = 1; String[] arguments = { user, password, host, dbname, dsn, projectspec, (getFinalSourceDirectory()).replaceAll("/", "@/") }; command.addArguments(arguments);//from ww w . java 2 s . co m try { exitStatus = commandLineExecutor.executeCommand(log, command, new File(getFinalSourceDirectory())); } catch (Exception e) { log.error("Failure executing Serena Command", e); return -1; } log.info("Exit Status=" + exitStatus); return exitStatus; }
From source file:com.sds.acube.ndisc.xmigration.util.XNDiscMigUtil.java
/** * console clear /*from ww w . j av a 2s . c o m*/ */ public static void clearConsoleOutput() { try { String os = System.getProperty("os.name").toLowerCase(); String ostype = (os.contains("windows")) ? "W" : "U"; if (ostype.equals("W")) { CommandLine cmdLine = CommandLine.parse("cls"); DefaultExecutor executor = new DefaultExecutor(); executor.execute(cmdLine); System.out.printf("%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n", new Object[0]); } else { CommandLine cmdLine = CommandLine.parse("clear"); DefaultExecutor executor = new DefaultExecutor(); executor.execute(cmdLine); System.out.print(CLEAR_TERMINAL_ANSI_CMD); System.out.flush(); } } catch (IOException e) { } }
From source file:com.github.brandtg.pantopod.tor.TorProxyManager.java
@Override public void start() throws Exception { synchronized (sync) { File dataDir = new File(torRootDir, String.format("tor_%d", socksPort)); pidFile = new File(dataDir, PID_FILE_NAME); if (pidFile.exists()) { LOG.info("Stopping existing process {}", pidFile); stopProcess(pidFile, 2 /* SIGINT */); }/*from w w w. j av a 2 s .c o m*/ LOG.info("Creating {}", dataDir); FileUtils.forceMkdir(dataDir); String command = torExecutable + " --RunAsDaemon 1" + " --CookieAuthentication 0" + " --HashedControlPassword \"\"" + " --ControlPort " + controlPort + " --PidFile " + pidFile.getAbsolutePath() + " --SocksPort " + socksPort + " --DataDirectory " + dataDir.getAbsolutePath(); LOG.info("Executing {}", command); DefaultExecutor executor = new DefaultExecutor(); int retCode = executor.execute(CommandLine.parse(command)); LOG.info("Executed {} #=> {}", command, retCode); // Set the system socket proxy System.setProperty("socksProxyHost", "localhost"); System.setProperty("socksProxyPort", String.valueOf(socksPort)); // Schedule a watchdog to periodically send SIGHUP, which resets the tor circuit if (watchdogDelayMillis > 0) { scheduler.schedule(new SigHupWatchdog(pidFile), watchdogDelayMillis, TimeUnit.MILLISECONDS); } } }
From source file:com.blackducksoftware.tools.scmconnector.integrations.subversion.SubversionConnector.java
private boolean repoExists(File targetDir) throws Exception { validateExecutableInstance(EXECUTABLE); CommandLine command = CommandLine.parse(EXECUTABLE); command.addArgument("status"); CommandResults commandResults;//ww w. j a v a 2 s. c om try { commandResults = commandLineExecutor.executeCommandForOutput(log, command, targetDir); } catch (Exception e) { log.error("Failure executing SVN Command", e); commandResults = null; } if (commandResults != null && commandResults.getStatus() == 0) { // warning message of form "svn: warning: W155007: 'C:\SVNFiles' is // not a working copy" only // printed when repository is not checked out to directory if (commandResults.getOutput().trim().contains("warning")) { log.info("repository does not exist in directory: " + targetDir.getAbsolutePath()); return false; } log.info("repository exists in directory: " + targetDir.getAbsolutePath()); return true; } else { log.info("repository does not exist in directory: " + targetDir.getAbsolutePath()); return false; } }
From source file:com.github.shyiko.hmp.AbstractHadoopMojo.java
protected void executeCommand(HadoopSettings hadoopSettings, String command, String automaticResponseOnPrompt, boolean bindProcessDestroyerToShutdownHook) throws IOException { if (getLog().isDebugEnabled()) { getLog().debug("Executing " + command); }// w ww. j av a 2 s . c om Executor executor = new DefaultExecutor(); executor.setStreamHandler(new ExecutionStreamHandler(quiet, automaticResponseOnPrompt)); executor.setWorkingDirectory(hadoopSettings.getHomeDirectory()); if (bindProcessDestroyerToShutdownHook) { executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); } executor.execute(CommandLine.parse(command), hadoopSettings.getEnvironment()); }
From source file:com.kotcrab.vis.editor.CrashReporter.java
private void restart() { new Thread(() -> { try {// ww w . j a v a 2s. c o m CommandLine cmdLine = CommandLine.parse(restartCommand); DefaultExecutor executor = new DefaultExecutor(); executor.execute(cmdLine); } catch (IOException e) { e.printStackTrace(); } }).start(); }
From source file:com.blackducksoftware.tools.scmconnector.integrations.teamfoundation.TeamFoundationConnector.java
@Override public int sync() { workspaceExists();// www . j a va 2 s. c o m if (!workspaceExists) { if (createWorkpace() != 0) { return 1; } if (mapWorkpace() != 0) { return 1; } } CommandLine command = CommandLine.parse(executable); String[] arguments = new String[] { "get", "-recursive", "-login:" + user + "," + password, getFinalSourceDirectory() }; command.addArguments(arguments, false); int exitStatus = 1; try { exitStatus = commandLineExecutor.executeCommand(log, command, new File(getFinalSourceDirectory())); } catch (Exception e) { log.error("Failure executing TF Command", e); } return exitStatus; }
From source file:com.github.brandtg.pantopod.tor.TorProxyManager.java
private static void stopProcess(File pidFile, int signalNumber) throws Exception { try (InputStream inputStream = new FileInputStream(pidFile)) { Integer pid = Integer.valueOf(IOUtils.toString(inputStream).trim()); String command = String.format("KILL -%d %d", signalNumber, pid); LOG.info("Executing {}", command); DefaultExecutor executor = new DefaultExecutor(); int retCode = executor.execute(CommandLine.parse(command)); LOG.info("{} exited with {}", command, retCode); } catch (Exception e) { LOG.error("Could not kill {}", pidFile, e); }/*from w w w .j a v a 2s .co m*/ }