我正在开发一个 Java 桌面应用程序来管理 iptables,并且我想通过 Java 执行 iptables 命令,这是我正在做的事情:
我从终端执行 gksu“iptables -L”并且它起作用了,但是当我尝试从 Java 运行时执行它(exec。(“gksu \“iptables -L \“”))时我不断收到此输出:
GKsu 版本 2.0.2
用法:gksu [-u] [选项]
--debug,-d
Print information on the screen that might be
useful for diagnosing and/or solving problems.
--用户,-u
Call <command> as the specified user.
--禁用抓取,-g
Disable the "locking" of the keyboard, mouse,
and focus done by the program when asking for
password.
--prompt,-P
Ask the user if they want to have their keyboard
and mouse grabbed before doing so.
–preserve-env,-k
Preserve the current environments, does not set $HOME
nor $PATH, for example.
--login,-l
Make this a login shell. Beware this may cause
problems with the Xauthority magic. Run xhost
to allow the target user to open windows on your
display!
--description , -D
Provide a descriptive name for the command to
be used in the default message, making it nicer.
You can also provide the absolute path for a
.desktop file. The Name key for will be used in
this case.
--消息,-m
Replace the standard message shown to ask for
password for the argument passed to the option.
Only use this if --description does not suffice.
–print-pass,-p
Ask gksu to print the password to stdout, just
like ssh-askpass. Useful to use in scripts with
programs that accept receiving the password on
stdin.
–sudo 模式,-S
Make GKSu use sudo instead of su, as if it had been
run as "gksudo".
--su 模式,-w
Make GKSu use su, instead of using libgksu's
default.
我希望有人能帮助我:D plox:P
答案1
你做得不对。创建一个字符串数组。第一个元素将是命令名称,后面的元素将是参数。http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String[])