我试图运行此行代码:的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