Problem with Java Runtime.exec() when trying to start Nmap.exe
-
25-09-2019 - |
Question
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..
Solution
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.