2016-06-08 154 views
0

我已經執行了批處理文件從命令提示符與winrs命令它執行得很好,當我執行相同的命令與java程序使用進程生成器,我越來越像指定的路徑IOException不可用 錯誤2指定的路徑未被availble的REG - 從java本地機器運行遠程批處理文件

java.io.IOException: Cannot run program "cmd /c C:\Windows\System32\winrs.exe -r:http://ipaddress:port -u:username -p:password dir": CreateProcess error=2, The system cannot find the file specifiedProgram terminated! 

at java.lang.ProcessBuilder.start(Unknown Source) 
at com.sample.CmdExec.main(CmdExec.java:28) 
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified 
at java.lang.ProcessImpl.create(Native Method) 
at java.lang.ProcessImpl.<init>(Unknown Source) 
at java.lang.ProcessImpl.start(Unknown Source) 
... 2 more 

回答

0

的ProcessBuilder不使用像

ProcessBuilder b = new ProcessBuilder("cmd /c C:\Windows\System32\winrs.exe -r:http://ipaddress:port -u:username -p:password dir"); 

一個完整的命令行,但需要可執行文件和分隔參數:

ProcessBuilder b = new ProcessBuilder("cmd", "/c", "C:\Windows\System32\winrs.exe", "-r:http://ipaddress:port", "-u:username", "-p:password", "dir"); 
相關問題