尝试启动 Nmap.exe 时 Java Runtime.exec() 出现问题
我正在使用 Java 1.6、Eclipse、Windows 7。 我正在尝试在 java 程序中运行命令来使用 NMAP。
代码:
<代码> String cmd[] = { "cmd.exe", "/c","启动notepad.exe"};
进程 pr = rt.exec(cmd);
工作正常,但代码:
String cmd[] = { "cmd.exe", "/c","启动nmap.exe"};
进程 pr = rt.exec(cmd); 根本
就没有。
我在命令提示符下尝试了这两个命令,它们都工作正常,但当我使用 Runtime.exec() 尝试时,后一个命令失败。会出现什么问题呢?
提前致谢..
I'm using Java 1.6 , Eclipse , Windows 7.
I'm trying to run commands in a java program to use NMAP.
The code :
String cmd[] = { "cmd.exe", "/c","start notepad.exe"};
Process pr = rt.exec(cmd);
works fine, but the code:
String cmd[] = { "cmd.exe", "/c","start nmap.exe"};
Process pr = rt.exec(cmd);
simply doesn't.
I tried both commands in the command prompt, they both work fine but the latter one fails when I try it with the Runtime.exec(). What would be the problem ?
Thanks, in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许“当 Runtime.exec() 不会” 可以帮助你。
该命令在命令 shell 中工作而不是在 Java 中工作的原因可能是命令 shell 的优点是能够引用 PATH 环境变量来查找它; Java 不能。我敢打赌,如果您输入 Nmap.exe 的完整路径,效果会更好。
Maybe "When Runtime.exec() won't" can help you.
The reason the command works in a command shell and not in Java might be that the command shell has the advantage of being able to refer to the PATH environment variable to find it; Java cannot. I'll bet if you put the full path to Nmap.exe that you'll fare better.