Here you can find the source of execShell(String cmd)
public static Process execShell(String cmd) throws IOException, InterruptedException
//package com.java2s; /*// w ww.ja va 2 s. co m * Newisys-Utils - Newisys Utility Classes * Copyright (C) 2005 Newisys, Inc. or its licensors, as applicable. * * Licensed under the Open Software License version 2.0 (the "License"); you * may not use this file except in compliance with the License. You should * have received a copy of the License along with this software; if not, you * may obtain a copy of the License at * * http://opensource.org/licenses/osl-2.0.php * * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ import java.io.IOException; public class Main { public static Process execShell(String cmd) throws IOException, InterruptedException { return Runtime.getRuntime().exec(getShellArgs(cmd)); } public static String[] getShellArgs(String cmd) { String osName = System.getProperty("os.name"); String[] args = new String[3]; if (osName.startsWith("Windows 9")) { args[0] = "command.com"; args[1] = "/C"; } else if (osName.startsWith("Windows")) { args[0] = "cmd.exe"; args[1] = "/C"; } else { args[0] = "/bin/sh"; args[1] = "-c"; } args[2] = cmd; return args; } }