Runs a shell command in the system and provides a StringBuffer
with the output of the command.

@param cmd an array of string that form the command to run

@return a StringBuffer that contains the output of the command
422452
public static StringBuffer runCommand(String[] cmd) {
    StringBuffer retval = new StringBuffer(MAX_OUTPUT_LENGTH);
    Process p;
    try {
      p = Runtime.getRuntime().exec(cmd);
      InputStream tmp = p.getInputStream();
      p.waitFor();
      int c;
      while ((c = tmp.read()) != -1)
        retval.append((char) c);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    return retval;
  }
243073
public String execute(String... command) {
        return commandProcessor.run(aCommand("VBoxManage").withArguments(command)).getOutput();
    }
762909
public Command[] toArgs(final String line) {
        if (line == null || line.isEmpty()) {
            throw new IllegalArgumentException("Empty command.");
        }

        final List<Command> commands = new ArrayList<>();
        final List<String> result = new ArrayList<>();
        final StringBuilder current = new StringBuilder();

        char waitChar = ' ';
        boolean copyNextChar = false;
        boolean inEscaped = false;
        for (final char c : line.toCharArray()) {
            if (copyNextChar) {
                current.append(c);
                copyNextChar = false;
            } else if (waitChar == c) {
                if (current.length() > 0) {
                    result.add(current.toString());
                    current.setLength(0);
                }
                waitChar = ' ';
                inEscaped = false;
            } else {
                switch (c) {
                    case '"':
                    case '\'':
                        if (!inEscaped) {
                            waitChar = c;
                            inEscaped = true;
                            break;
                        } else {
                            current.append(c);
                        }
                        break;

                    case '\\':
                        copyNextChar = true;
                        break;

                    case '|':
                        flush(commands, result, current);
                        break;

                    default:
                        current.append(c);
                }
            }
        }

        if (waitChar != ' ') {
            throw new IllegalStateException("Missing closing " + Character.toString(waitChar));
        }

        flush(commands, result, current);
        return commands.toArray(new Command[commands.size()]);
    }
28311
protected Pair<Integer, InputStream> executeCommand(String command) {
        int resultVal = 1;
        InputStream inputStream = null;
        try {
            logger.debug("Executing command: {}", command);
            Process process =  Runtime.getRuntime().exec(command);

            resultVal = process.waitFor();
            inputStream = process.getInputStream();

        } catch (InterruptedException e) {
            logger.info("Execution of {} failed: code - {} ; message - {}", command, resultVal, e.getMessage());
            Thread.currentThread().interrupt();
        } catch (IOException  e) {
            logger.info("Execution of {} failed: code - {} ; message - {}", command, resultVal, e.getMessage());
        }
        if (inputStream == null) {
           // Create an empty InputStream instead of returning a null
           inputStream = new InputStream() {
               @Override
               public int read() throws IOException {
                   return -1;
               }
           } ;
        }
        return new Pair<>(resultVal, inputStream);
    }
319881
public static void runShellCommand(String cmd,
                                     StringBuilder outputLines,
                                     StringBuilder errorLines)
    throws IOException {
    runShellCommand(new String[] {cmd}, outputLines, errorLines);
  }
128087
def output_for(cmd, options = {})
      output = StringIO.new
      execute(cmd, options.merge(:outstream => output))
      output.string
    end
1299013
def shell(cmd):
    
    adb_full_cmd = [v.ADB_COMMAND_PREFIX, v.ADB_COMMAND_SHELL, cmd]
    return _exec_command(adb_full_cmd)
311826
def run_cmd(command, verbose=True, shell='/bin/bash'):
    """"""
    process = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT, executable=shell)
    output = process.stdout.read().decode().strip().split('\n')
    if verbose:
        # return full output including empty lines
        return output
    return [line for line in output if line.strip()]
859344
private void replaceCommandLine(String replacement) {
		int currentCLSize = commandLineBuffer.size();
		commandLineBuffer = new ByteArrayOutputStream();
		for (int x = 0; x < replacement.length(); x++) {
			commandLineBuffer.write(replacement.charAt(x));
		}
		String replaceString = '\r' + promptStr;
		for (int x = 0; x <= currentCLSize; x++) {
			replaceString += ' ';
		}
		replaceString += '\r' + promptStr + replacement;
		ps.print(replaceString);
	}
1138476
function exec(cmd) {
    const ret = shell.exec(cmd, {
        silent: true
    });

    if (ret.code != 0) {
        console.error("Error:", ret.stdout, ret.stderr);
        process.exit(1);
    }
    return ret;
}
341690
public static Process exec(String[] envp, File dir, String... cmds) {
		if (ArrayUtil.isEmpty(cmds)) {
			throw new NullPointerException("Command is empty !");
		}

		// 单条命令的情况
		if (1 == cmds.length) {
			final String cmd = cmds[0];
			if (StrUtil.isBlank(cmd)) {
				throw new NullPointerException("Command is empty !");
			}
			cmds = StrUtil.splitToArray(cmd, StrUtil.C_SPACE);
		}
		try {
			return Runtime.getRuntime().exec(cmds, envp, dir);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
1179050
public static Process exec(String... cmds) {
		if (ArrayUtil.isEmpty(cmds)) {
			throw new NullPointerException("Command is empty !");
		}

		// 单条命令的情况
		if (1 == cmds.length) {
			final String cmd = cmds[0];
			if (StrUtil.isBlank(cmd)) {
				throw new NullPointerException("Command is empty !");
			}
			cmds = StrUtil.splitToArray(cmd, StrUtil.C_SPACE);
		}

		Process process;
		try {
			process = new ProcessBuilder(cmds).redirectErrorStream(true).start();
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
		return process;
	}
1310231
protected function _exec($cmd, $input = "")
        {
            $result = array(
                'stdout' => '',
                'stderr' => '',
                'return' => ''
            );

            $proc = proc_open(
                $cmd,
                array(
                    0 => array(
                        'pipe',
                        'r'
                    ),
                    1 => array(
                        'pipe',
                        'w'
                    ),
                    2 => array(
                        'pipe',
                        'w'
                    )
                ),
                $pipes
            );
            fwrite($pipes[0], $input);
            fclose($pipes[0]);

            $result['stdout'] = stream_get_contents($pipes[1]);
            fclose($pipes[1]);

            $result['stderr'] = stream_get_contents($pipes[2]);
            fclose($pipes[2]);

            $result['return'] = proc_close($proc);

            return $result;
        }
39167
protected void process(String cmd) {
        int firstSpace = cmd.indexOf(' ');
        if(firstSpace < 0) firstSpace = cmd.length();

        CommandInfo info = commands.get(cmd.substring(0, firstSpace).toUpperCase());

        if(info == null) {
            sendResponse(502, "Unknown command");
            return;
        }

        processCommand(info, firstSpace != cmd.length() ? cmd.substring(firstSpace + 1) : "");
    }
788225
def run_cmd(cmd, out=os.path.devnull, err=os.path.devnull):
    

    logger.debug(' '.join(cmd))
    with open(out, 'w') as hout:
        proc = subprocess.Popen(cmd, stdout=hout, stderr=subprocess.PIPE)
        err_msg = proc.communicate()[1].decode()
    with open(err, 'w') as herr:
        herr.write(str(err_msg))
    msg = '({}) {}'.format(' '.join(cmd), err_msg)
    if proc.returncode != 0:
        logger.error(msg)
        raise RuntimeError(msg)
2522
public function exec($cmd, $args = array())
    {
        // Arguments must be safe
        if (!is_array($args)) {
            $args = array($args);
        }
        foreach ($args as $val) {
            if (!is_string($val)) {
                throw new BaseException('You must specify arguments as strings');
            }
            $this->args[] = escapeshellarg($val);
        }

        // Command myst be safe
        $this->cmd = escapeshellcmd($cmd);

        $this->debug('Executing '.$cmd.($this->args ? ' '.implode(' ', $this->args) : ''));
        // Now do the execution
        $this->executeRaw($this->cmd.' '.implode(' ', $this->args));

        return $this;
    }
581831
public static List<String> constructCommandAsList_Windows_cmd (String command) {
		List<String> commandAsList = new ArrayList<String> ();

		commandAsList.add ("cmd");
		commandAsList.add ("/c");
		commandAsList.add (command);

		return commandAsList;
	}