Java exec exeCmdByOs(String cmd)

Here you can find the source of exeCmdByOs(String cmd)

Description

exe Cmd By Os

License

Open Source License

Declaration

public static Process exeCmdByOs(String cmd) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

public class Main {
    public static Process exeCmdByOs(String cmd) throws IOException {
        Process process = null;//from w w  w .j  av a2 s  .c  o  m

        Runtime runtime = Runtime.getRuntime();

        String osName = System.getProperty("os.name");

        if (osName.toLowerCase().startsWith("win")) {
            process = runtime.exec((new String[] { "cmd", "/C", cmd }));
        } else {
            process = runtime.exec((new String[] { "sh", "-c", cmd }));
        }
        return process;
    }
}

Related

  1. execGetOutput(String[] command, String[] env)
  2. execHostName(String execCommand)
  3. execIt(String cmd)
  4. execJAR(String jarPath, String vmArgs, String appArgs, String workDir)
  5. execLocalhostCmd(String cmd)
  6. execName()
  7. execPrint(final boolean out, final String... command)
  8. execProcess(String process)
  9. execProcess(String[] cmdline, final long timeout)