「Java」Runtime.getRuntime().execメソッドを使う方法

2021年11月5日

サンプルコード:

public Process exec(String command, String[] envp, File dir) throws IOException {
  if (command.length() == 0) throw new IllegalArgumentException("Empty command");
  StringTokenizer st = new StringTokenizer(command);
  String[] cmdarray = new String[st.countTokens()];
  for (int i = 0; st.hasMoreTokens(); i++)
    cmdarray[i] = st.nextToken();
    return exec(cmdarray, envp, dir);
 }
}

オーバーロード方法:

public Process exec(String command)
public Process exec(String [] cmdArray)
public Process exec(String command, String [] envp)
public Process exec(String [] cmdArray, String [] envp)
public Process exec(String command,String[] envp,File dir)
public Process exec(String[] cmdarray,String[] envp,File dir)

 

Java

Posted by arkgame