close

在c/c++中, 我們可以藉由system()執行ㄧ些作業系統上的指令 , 

同樣地 , 在Java中也有屬於自己的方式來進行操作 , 那就是藉由Process與Runtime.exec().

 

Process process = Runtime.getRuntime().exec("xxx.exe");

process.waitfor();

其中Runtime.getRuntime().exec("xxx.exe")代表的是創立ㄧ個subprocess來

執行此ㄧ外部程序 , 而Runtime.getRuntime().exec()會return ㄧ個process ,

這個process可以用來得到該command所產生在standard output的訊息,

另外process.waitfor()的作用是在於讓process等待subprocess執行完後再往下執行.

 

 

ref : http://www.cnblogs.com/xxpal/articles/824963.html

ref : http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Process.html

arrow
arrow
    全站熱搜

    JerryCheng 發表在 痞客邦 留言(1) 人氣()