2012-09-10 244 views
0

我需要執行此命令來停止硒服務器。如何從Java程序執行命令

wmic path win32_process Where "CommandLine Like '%selenium-server%'" Call Terminate 

從我的Java程序。我試圖

Runtime.getRuntime().exec("command as a single string escaped") 

Runtime.getRuntime().exec(String[]) 

但沒有得到執行。當我從cmd執行相同的命令時,它工作正常。有人可以請幫助。

回答

0

你可以嘗試使用this one

public Process exec(String[] cmdarray, String[] envp, File dir) 
    throws IOException 

執行指定的命令和參數在一個單獨的進程 指定環境和工作目錄。

然後等待過程結束使用process.waitFor()方法。