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

booleanexec(String cmd)
exec
try {
    String cmds[] = null;
    if (isNT()) {
        cmds = new String[3];
        cmds[0] = "cmd";
        cmds[1] = "/c";
        cmds[2] = cmd;
    } else {
...
Processexec(String cmd, File dir)
exec
return exec(cmd, dir, System.out, null);
Stringexec(String command)
exec
String ls = System.getProperty("line.separator");
StringBuffer result = new StringBuffer();
ArrayList<String> argsArray = new ArrayList<String>();
StreamTokenizer st = new StreamTokenizer(new StringReader(command));
st.resetSyntax();
st.wordChars('a', 'z');
st.wordChars('A', 'Z');
st.wordChars('0', '9');
...
Processexec(String command)
exec
return exec(command, null);
Stringexec(String command)
exec
try {
    Process process = Runtime.getRuntime().exec(command);
    InputStream errorStream = process.getErrorStream();
    byte[] buffer = new byte[1024];
    int readBytes;
    StringBuilder stringBuilder = new StringBuilder();
    while ((readBytes = errorStream.read(buffer)) > 0) {
        stringBuilder.append(new String(buffer, 0, readBytes));
...
voidexec(String command)
Utility function for debugging.
try {
    Process p = Runtime.getRuntime().exec(command);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    while ((command = stdInput.readLine()) != null) {
        System.err.println(command);
    while ((command = stdError.readLine()) != null) {
...
Listexec(String command)
exec
try {
    List<String> retList = new ArrayList<String>();
    String line;
    Process p = Runtime.getRuntime().exec(command);
    BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    while ((line = bri.readLine()) != null) {
        retList.add(line);
...
Processexec(String command)
exec
return Runtime.getRuntime().exec(command);
intexec(String command, String workingDir)
exec
try {
    Process process = Runtime.getRuntime().exec(command, null,
            workingDir != null ? new File(workingDir) : null);
    BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String brline;
    while ((brline = br.readLine()) != null) {
        System.out.println(brline);
    br = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    while ((brline = br.readLine()) != null) {
        System.out.println(brline);
    process.waitFor();
    return process.exitValue();
} catch (IOException e) {
    throw new RuntimeException(e);
} catch (InterruptedException e) {
    throw new RuntimeException(e);
Processexec(String command, String[] args_, String[] environment)
Executes the commands with args and environemnt in a separate process.
String[] args = new String[1];
if (args_ != null) {
    args = new String[args_.length + 1];
    for (int i = 0; i < args_.length; i++)
        args[i + 1] = args_[i];
args[0] = command;
return Runtime.getRuntime().exec(args, environment);
...