簡體   English   中英

試圖在Java中執行批處理文件

[英]trying to execute a batch file in java

為什么該代碼不起作用?

Process p1 = Runtime.getRuntime().exec("switchCon.bat");

這是該文件的路徑:

C:\Users\Administrator\Desktop\switchCon.bat

該文件如下所示:

netsh interface ip set address "Local Area Connection 2" static 147.8.178.231 255.255.255.0 147.8.176.1 1

嘗試指定bat文件的完整路徑,如下所示:

Process p1 = Runtime.getRuntime().exec("C:\\Users\\Administrator\Desktop\\switchCon.bat");

這個怎么樣:

Process pr;
Runtime run = Runtime.getRuntime();
pr = run.exec("cmd.exe /c C:\\Users\\Administrator\\Desktop\\switchCon.bat"); 
pr.waitFor();

或這個:

Process pr;
Runtime run = Runtime.getRuntime();
pr = run.exec("cmd.exe /c netsh interface ip set address "Local Area Connection 2" static 147.8.178.231 255.255.255.0 147.8.176.1 1"); 
pr.waitFor();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM