Reputation: 11
I'm going to add some rules in my firewall with java, I'd like to execute this command with java:
String [] cmd = {"sudo ipfw delete 100 "};
Runtime.getRuntime().exec(cmd);
But I get this error
Cannot run program "sudo ipfw delete 100 ": error=2, No such file or directory
Any suggestion?
Upvotes: 1
Views: 336
Reputation: 159784
This is common error output for Runtime.exec on *nix platforms. Ensure that both sudo
and ipfw
are on your path in your runtime environment.
Alternatively you could specify the full path locations:
String [] cmd = {"/path_to_sudo/sudo", "/path_to_ipfw/ipfw", "delete", "100"};
Wrt the password for sudo
, you could have the password in your command although there is a clear security risk with this(!)
One solution is to read the password from your application.
Upvotes: 1
Reputation: 3311
I would try the full path to ipfw /sbin/ipfw and possibly sudo as well.
One question would be how do you plan to deal with entering the password like this?
Upvotes: 0