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

Processexec(String command[], boolean stop)
exec
Process p = Runtime.getRuntime().exec(command);
if (stop)
    p.waitFor();
return p;
voidexec(String exec)
exec
new ProcessBuilder(exec).start();
Processexec(String program, String... args)
exec
if (args != null) {
    List<String> array = new ArrayList<String>(args.length);
    for (int i = 0; i < args.length; i++) {
        array.add(args[i]);
    return exec(program, array);
return exec(program, (List<String>) null);
...
intexec(String pwd, boolean quiet, String... command)
Execute command
try {
    ProcessBuilder builder = new ProcessBuilder(command);
    builder = builder.directory(new File(pwd));
    if (!quiet)
        builder = builder.inheritIO();
    Process proc = builder.start();
    return proc.waitFor();
} catch (IOException | InterruptedException e) {
...
Stringexec(String... _command)
exec
final ProcessBuilder pb = new ProcessBuilder(_command);
final Process p = pb.start();
p.waitFor();
final StringWriter writer = new StringWriter();
writeStream(p.getInputStream(), writer);
return writer.toString();
Stringexec(String... args)
A simple debugging utility used to obtain information about the execution environment that's only available through some system utility, like netstat, or jps, etc.
final ByteArrayOutputStream bao = new ByteArrayOutputStream(1024);
final PrintStream output = new PrintStream(bao);
try {
    final ProcessBuilder builder = new ProcessBuilder(args);
    builder.redirectErrorStream(true);
    final Process process = builder.start();
    final InputStream is = process.getInputStream();
    final InputStreamReader isr = new InputStreamReader(is);
...
Stringexec(String... cmd)
exec
StringBuffer resultBuffer = new StringBuffer();
Process pr = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
    resultBuffer.append(line + "<br />");
in.close();
...
Stringexec(String... cmdarray)
exec
try {
    Process process = Runtime.getRuntime().exec(cmdarray);
    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    StringBuilder sb = new StringBuilder();
    String s;
    while ((s = reader.readLine()) != null) {
        if (s.length() > 0) {
            if (sb.length() > 0)
...
intexec(String... command)
exec
try {
    return Integer.parseInt(new Scanner(Runtime.getRuntime().exec(command).getInputStream()).next());
} catch (IOException e) {
    throw new RuntimeException("Failed to read output from " + Arrays.toString(command));
Stringexec(String... command)
exec
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
InputStream in = null;
StringBuilder result;
try {
    in = p.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String line = null;
...