我試圖運行此行代碼:的Java調用Runtime.getRuntime()上的Windows錯誤EXEC
Process p = Runtime.getRuntime().exec(new String[] {"nmap -sP 192.168.1.0/24", g});
上面給出了這樣的錯誤:
Exception in thread "main" java.io.IOException: Cannot run program "nmap -sP 192.168.1.0/24": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Test.main(Test.java:14)
然而,這行代碼正常工作:
Process p = Runtime.getRuntime().exec(new String[] {"nmap", g});
這裏有一些細節:
- 已安裝nmap 5.51從'cmd線'完美工作。
- Windows Vista。
可能重複[如何執行命令與參數?](http://stackoverflow.com/questions/7134486/how-to-execute-command-with-parameters) – Raedwald