java----調用windows的DOS命令並回顯/啟動和關閉appium

來源:互聯網
上載者:User

標籤:學習記錄

/** *  Java調用windows的DOS命令 *  實現調用Windows的ipconfig命令,然後將輸出的資訊通過IO流輸出到控制台。 *  實現啟動appium服務 *  實現關閉appium服務 */public class Doc {    public static void main(String[] args) throws Exception {         String cmd = "ping www.baidu.com";         String cmd1= "cmd /c appium";           String cmd2="taskkill /F /IM node.exe";         //         dosStartAndPrintResult(cmd2);//         Thread.sleep(5000);         dosStartAndPrintResult(cmd1);         Thread.sleep(3000);         dosStartAndPrintResult(cmd2);            }        /**傳入一個命令,執行dos命令並回顯*/    public static void dosStartAndPrintResult (String cmd){                try {            Runtime rt = Runtime.getRuntime(); // 擷取運行時系統              Process proc = rt.exec(cmd);//執行命令            BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream(), Charset.forName("GBK")));//解決列印結果亂碼的問題            //回顯dos命令執行後的結果            String line = null;              while ((line = br.readLine()) != null) { // 列印出命令執行的結果                  System.out.println(line);              }          } catch (IOException e) {            e.printStackTrace();        }     }        }===================啟動appium**執行結果===========================[Appium] Welcome to Appium v1.6.5[Appium] Appium REST http interface listener started on 0.0.0.0:4723===================ping百度**執行結果===========================正在 Ping www.a.shifen.com [220.181.112.244] 具有 32 位元組的資料:來自 220.181.112.244 的回複: 位元組=32 時間=2ms TTL=55來自 220.181.112.244 的回複: 位元組=32 時間=2ms TTL=55來自 220.181.112.244 的回複: 位元組=32 時間=4ms TTL=55來自 220.181.112.244 的回複: 位元組=32 時間=1ms TTL=55220.181.112.244 的 Ping 統計資訊:    資料包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),往返行程的估計時間(以毫秒為單位):    最短 = 1ms,最長 = 4ms,平均 = 2ms    ===================關閉appium**執行結果===========================成功: 已終止進程 "node.exe",其 PID 為 42808。



java----調用windows的DOS命令並回顯/啟動和關閉appium

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.