Java執行exe,bat等可執行檔案

iandshe發表於2008-07-27


Process proc = Runtime.getRuntime().exec(command);

[@more@]

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CallExe {
public static void main(String[] args) {
String text = null;
String command = "C:Program FilesYodaoDeskDictRunDict.exe";//exe,bat檔名OR DOS命令
try {
Process proc = Runtime.getRuntime().exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((text = in.readLine())!= null) {
System.out.println(text); //輸出測試
}
} catch (IOException ioError) {
ioError.printStackTrace();
System.exit(0);
}

}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7313961/viewspace-1007942/,如需轉載,請註明出處,否則將追究法律責任。

相關文章