public String toString() { return StringUtils.join( getShellCommandline(), " " ); }
/** * Returns the executable and all defined arguments.<br> * For Windows Family, {@link Commandline#getShellCommandline()} is returned */ public String[] getCommandline() { if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) { return getShellCommandline(); } final String[] args = getArguments(); String executable = getLiteralExecutable(); if ( executable == null ) { return args; } final String[] result = new String[args.length + 1]; result[0] = executable; System.arraycopy( args, 0, result, 1, args.length ); return result; }
public void assertCommandLine( String expectedCommand, File expectedWorkingDirectory, Commandline actualCommand ) throws IOException { Commandline cl = new Commandline( expectedCommand ); if ( expectedWorkingDirectory != null ) { cl.setWorkingDirectory( expectedWorkingDirectory.getAbsolutePath() ); } String expectedCommandLineAsExecuted = StringUtils.join( cl.getShellCommandline(), " " ); String actualCommandLineAsExecuted = StringUtils.join( actualCommand.getShellCommandline(), " " ); assertEquals( expectedCommandLineAsExecuted, actualCommandLineAsExecuted ); }
public Process start() throws ExecutionException { Commandline commandline = getCommandLine(); String[] shellCommandline = commandline.getShellCommandline(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(PHANTOMJS_COMMAND, Arrays.asList(shellCommandline)); } ProcessBuilder processBuilder = new ProcessBuilder(shellCommandline); if (commandline.getWorkingDirectory() != null) { processBuilder.directory(commandline.getWorkingDirectory()); } try { return processBuilder.start(); } catch(IOException e) { throw new ExecutionException(UNABLE_TO_START,e); } }
public void assertCommandLine( String expectedCommand, File expectedWorkingDirectory, Commandline actualCommand ) throws IOException { Commandline cl = new Commandline( expectedCommand ); if ( expectedWorkingDirectory != null ) { cl.setWorkingDirectory( expectedWorkingDirectory.getAbsolutePath() ); } String expectedCommandLineAsExecuted = StringUtils.join( cl.getShellCommandline(), " " ); String actualCommandLineAsExecuted = StringUtils.join( actualCommand.getShellCommandline(), " " ); assertEquals( expectedCommandLineAsExecuted, actualCommandLineAsExecuted ); }
public static void executeCommand(Commandline commandline, StreamConsumer outConsumer, StreamConsumer errorConsumer, boolean isVerbose) throws CommandLineException { if (isVerbose) { System.out.println("Executing command:\n" + StringUtils.join(commandline.getShellCommandline(), " ")); } int returnCode = CommandLineUtils.executeCommandLine(commandline, outConsumer, errorConsumer, 1800); if (returnCode != 0) { String msg = "Failed to deploy, return code: " + returnCode + ". Please make sure target WAS is alive and reachable."; throw new WebSphereServiceException(msg); } else { System.out.println("Return code: " + returnCode); } }
/** * Command line execution without system input * * @param cli a command line to execute * @param systemOut standard output for a <code>C</code> style program * @param systemErr standard error for a <code>C</code> style program * @return The return status of the executed program, <code>0</code> is success * @throws CommandLineException when a command line encountered */ public int execute( Commandline cli, StreamConsumer systemOut, StreamConsumer systemErr ) throws CommandLineException { if ( getLogger().isDebugEnabled() ) { getLogger().debug( "Executing: " + StringUtils.join( cli.getShellCommandline(), " " ) ); } return CommandLineUtils.executeCommandLine( cli, systemOut, systemErr ); }
/** * Command line execution with system input * * @param cli a command line to execute * @param systemIn standard input for a <code>C</code> style program * @param systemOut standard output for a <code>C</code> style program * @param systemErr standard error for a <code>C</code> style program * @return The return status of the executed program, <code>0</code> is success * @throws CommandLineException when a command line encountered */ public int execute( Commandline cli, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr ) throws CommandLineException { if ( getLogger().isDebugEnabled() ) { getLogger().debug( "Executing: " + StringUtils.join( cli.getShellCommandline(), " " ) ); } return CommandLineUtils.executeCommandLine( cli, systemIn, systemOut, systemErr ); }