Java Utililty Methods exec

List of utility methods to do exec

Description

The list of methods to do exec are organized into topic(s).

Method

voidexec(ArrayList args, File path)
exec
ProcessBuilder ps = new ProcessBuilder(args);
ps.redirectErrorStream(true);
if (path != null) {
    ps.directory(path);
Process pr = ps.start();
BufferedReader ins = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line;
...
Processexec(File dir, String cmd)
exec
String fullCmd = dir.getPath() + "/" + cmd;
Runtime runtime = Runtime.getRuntime();
return runtime.exec(fullCmd);
byte[]exec(final String cmd, final String[] args, final byte[] in, final File dir)
Creates and runs a new Process with the given arguments, taking cmd as a pattern for String#format(String,Object) with arguments args .
final StringBuilder sb = new StringBuilder();
if (cmd.contains(" ")) {
    sb.append('"' + cmd + '"');
} else {
    sb.append(cmd);
for (final String arg : args) {
    sb.append(' ' + arg);
...
Stringexec(List cmd, File binDir, File workDir, boolean parseOutput, boolean tossErrorOutput)
exec
String[] cmdp = cmd.toArray(new String[cmd.size()]);
String[] envp = { "PATH=" + binDir.getAbsolutePath() };
Process proc = Runtime.getRuntime().exec(cmdp, envp, workDir);
if (tossErrorOutput) {
    pullStream(proc.getErrorStream());
try {
    int err = proc.waitFor();
...
BufferedReaderexec(String args)
exec
String[] splitArgs = args.split(" ");
ProcessBuilder builder = new ProcessBuilder(splitArgs);
Process p = builder.start();
p.getOutputStream().flush();
p.getOutputStream().close();
return new BufferedReader(new InputStreamReader(p.getInputStream()));
Processexec(String cmd)
Execute a system command and return the attached process.
return exec(cmd, ".");
String[]exec(String cmd)
exec
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = null;
StringBuilder sbout = new StringBuilder();
while ((s = stdInput.readLine()) != null) {
    sbout.append(s);
StringBuilder sberr = new StringBuilder();
BufferedReader stdErrIn = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((s = stdErrIn.readLine()) != null) {
    sberr.append(s);
String[] ret = new String[2];
ret[0] = sbout.toString();
ret[1] = sberr.toString();
return ret;
voidexec(String cmd)
exec
try {
    Process child = Runtime.getRuntime().exec(cmd);
    child.waitFor();
    InputStream in = child.getInputStream();
    int c;
    while ((c = in.read()) != -1) {
        System.out.print(c);
    in.close();
} catch (IOException e) {
    System.err.println("Error: could execute command: " + cmd);
    e.printStackTrace();
} catch (InterruptedException e) {
    System.err.println("Error: command interrupted: " + cmd);
    e.printStackTrace();
Stringexec(String cmd)
exec
Process process = null;
List<String> processList = new ArrayList<String>();
try {
    process = Runtime.getRuntime().exec(cmd);
    BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String line = "";
    while ((line = input.readLine()) != null) {
        processList.add(line);
...
Stringexec(String cmd)
exec
try {
    String[] cmdA = { "/bin/sh", "-c", cmd };
    Process process = Runtime.getRuntime().exec(cmdA);
    LineNumberReader br = new LineNumberReader(new InputStreamReader(process.getInputStream()));
    StringBuffer sb = new StringBuffer();
    String line;
    while ((line = br.readLine()) != null) {
        System.out.println(line);
...