문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top