src/com/esotericsoftware/scar/Scar.java
static public String shell (Map<? extends String, ? extends String> env, String... command) throws IOException {
		if (command == null) throw new IllegalArgumentException("command cannot be null.");
		if (command.length == 0) throw new IllegalArgumentException("command cannot be empty.");

		String originalCommand = command[0];
		command[0] = resolvePath(command[0]);
		if (!fileExists(command[0]) && isWindows) {
			command[0] = resolvePath(command[0] + ".exe");
			if (!fileExists(command[0])) command[0] = originalCommand;
		}

		if (TRACE) {
			StringBuilder buffer = new StringBuilder(256);
			for (String text : command) {
				buffer.append(text);
				buffer.append(' ');
			}
			trace("scar", "Executing command: " + buffer);
		}
		ProcessBuilder builder = new ProcessBuilder(command).redirectErrorStream(true);
		if (env != null) {
			builder.environment().putAll(env);
		}
		final Process process = builder.start();
		final StringBuilder outputBuffer = new StringBuilder(512);
		new Thread("shell") {
			public void run () {
				BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
				try {
					while (true) {
						String line = reader.readLine();
						if (line == null) break;
						if (INFO && (line.length() > 0 || outputBuffer.length() > 0)) info("scar", line);
						outputBuffer.append(line);
						outputBuffer.append('\n');
					}
					reader.close();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}.start();

		try {
			process.waitFor();
		} catch (InterruptedException ignored) {
		}
		if (process.exitValue() != 0) {
			StringBuilder buffer = new StringBuilder(256);
			for (String text : command) {
				buffer.append(text);
				buffer.append(' ');
			}
			throw new RuntimeException("Error executing command: " + buffer);
		}
		return outputBuffer.toString();
	}
/** Executes the specified shell command with the specified environment variables. {@link #resolvePath(String)} is used to
	 * locate the file to execute. If not found, on Windows the same filename with an "exe" extension is also tried.
	 * @param env May be null. */
Executes the specified shell command with the specified environment variables.  #resolvePath(String) is used to
locate the file to execute. If not found, on Windows the same filename with an "exe" extension is also tried.
@param env May be null.
Executes the specified shell command with the specified environment variables . #resolvePath ( String ) is used to locate the file to execute . If not found on Windows the same filename with an " exe " extension is also tried . @param env May be null .
static public String shell (Map<? extends String, ? extends String> env, String... command) throws IOException {
		if (command == null) throw new IllegalArgumentException("command cannot be null.");
		if (command.length == 0) throw new IllegalArgumentException("command cannot be empty.");
		String originalCommand = command[0];
		command[0] = resolvePath(command[0]);
		if (!fileExists(command[0]) && isWindows) {
			command[0] = resolvePath(command[0] + ".exe");
			if (!fileExists(command[0])) command[0] = originalCommand;
		}
		if (TRACE) {
			StringBuilder buffer = new StringBuilder(256);
			for (String text : command) {
				buffer.append(text);
				buffer.append(' ');
			}
			trace("scar", "Executing command: " + buffer);
		}
		ProcessBuilder builder = new ProcessBuilder(command).redirectErrorStream(true);
		if (env != null) {
			builder.environment().putAll(env);
		}
		final Process process = builder.start();
		final StringBuilder outputBuffer = new StringBuilder(512);
		new Thread("shell") {
			public void run () {
				BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
				try {
					while (true) {
						String line = reader.readLine();
						if (line == null) break;
						if (INFO && (line.length() > 0 || outputBuffer.length() > 0)) info("scar", line);
						outputBuffer.append(line);
						outputBuffer.append('\n');
					}
					reader.close();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}.start();
		try {
			process.waitFor();
		} catch (InterruptedException ignored) {
		}
		if (process.exitValue() != 0) {
			StringBuilder buffer = new StringBuilder(256);
			for (String text : command) {
				buffer.append(text);
				buffer.append(' ');
			}
			throw new RuntimeException("Error executing command: " + buffer);
		}
		return outputBuffer.toString();
	}
static public String shell ( Map < ? extends String , ? extends String > env , String ... command ) throws IOException { if ( command == null ) throw new IllegalArgumentException ( "command cannot be null." ) ; if ( command . length == 0 ) throw new IllegalArgumentException ( "command cannot be empty." ) ; String originalCommand = command [ 0 ] ; command [ 0 ] = resolvePath ( command [ 0 ] ) ; if ( ! fileExists ( command [ 0 ] ) && isWindows ) { command [ 0 ] = resolvePath ( command [ 0 ] + ".exe" ) ; if ( ! fileExists ( command [ 0 ] ) ) command [ 0 ] = originalCommand ; } if ( TRACE ) { StringBuilder buffer = new StringBuilder ( 256 ) ; for ( String text : command ) { buffer . append ( text ) ; buffer . append ( ' ' ) ; } trace ( "scar" , "Executing command: " + buffer ) ; } ProcessBuilder builder = new ProcessBuilder ( command ) . redirectErrorStream ( true ) ; if ( env != null ) { builder . environment ( ) . putAll ( env ) ; } final Process process = builder . start ( ) ; final StringBuilder outputBuffer = new StringBuilder ( 512 ) ; new Thread ( "shell" ) { public void run ( ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( process . getInputStream ( ) ) ) ; try { while ( true ) { String line = reader . readLine ( ) ; if ( line == null ) break ; if ( INFO && ( line . length ( ) > 0 || outputBuffer . length ( ) > 0 ) ) info ( "scar" , line ) ; outputBuffer . append ( line ) ; outputBuffer . append ( '\n' ) ; } reader . close ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } } . start ( ) ; try { process . waitFor ( ) ; } catch ( InterruptedException ignored ) { } if ( process . exitValue ( ) != 0 ) { StringBuilder buffer = new StringBuilder ( 256 ) ; for ( String text : command ) { buffer . append ( text ) ; buffer . append ( ' ' ) ; } throw new RuntimeException ( "Error executing command: " + buffer ) ; } return outputBuffer . toString ( ) ; }
Executes the specified shell command with the specified environment variables.
Executes the specified shell command with the specified environment variables .