Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm working on a Java desktop aplication to manage iptables and i want to execute iptables commands via Java, this is what i am doing:

i execute from terminal gksu "iptables -L" and it worked but when i try to execute it from Java runtime ( exec.("gksu \"iptables -L\" ") ) i keep getting this output:

GKsu version 2.0.2

Usage: gksu [-u ] [options]

--debug, -d

Print information on the screen that might be

useful for diagnosing and/or solving problems.

--user , -u

Call <command> as the specified user.

--disable-grab, -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.

--message , -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-mode, -S

Make GKSu use sudo instead of su, as if it had been

run as "gksudo".

--su-mode, -w

Make GKSu use su, instead of using libgksu's

default.

I hope someone can help me :D plox :P

share|improve this question
add comment

1 Answer

You are not doing it right. Make a string array. The first element will be the command name, and the following elements will be arguments. http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String[])

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.