0

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..

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer ! I read that article many times but couldn't find the answer in there. Unfortunately, I think, the problem is not about that 4 pitfalls. What I don't understand is why the same type of command works with a native program like notepad and doesn't with NMAP. When using Runtime.exec(), windows simply forgets the whereabouts of NMAP. I'm getting a error that says "Windows cannot find 'nmap.exe'. Make sure you typed the name correctly, and then try again". But the same command works with the command prompt.
"I'm getting a error that says "Windows cannot find 'nmap.exe'." - Then the problem is clearly that nmap.exe cannot be found on the PATH that cmd.exe is using when executed via Process.exec(...). Use the full pathname for nmap.exe and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.