salut à tous,

je trouve un programme qu'execute la commande shell de linux en java,

tout les commandes marchent bien mais j'ai un probleme au niveau de iptables.

voir le code main:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
public class iptables {
    public static void main(String args[])
    {
        try{
Runtime runtime = Runtime.getRuntime();
//String cmdline= "sh ~/home/atoui/iptables.sh";
//String[] cmd1 = { "/bin/sh", "-c", "ping 192.168.1.1"};
String[] cmd = { "/bin/sh", "-c", "sudo iptables -A INPUT -d 192.168.1.7 -j DROP >fichier.txt" };
Process p = runtime.exec(cmd);
Thread stdTh = new InputStreamConsumerThread("STDStream", p.getInputStream(), System.out);
Thread errTh = new InputStreamConsumerThread("ErrorStream", p.getErrorStream(), System.out);
errTh.start();
stdTh.start();
 
// Attends la fin du process
p.waitFor();
 
 
 
}catch(Exception e) {
System.out.println("erreur d'execution");
}
    }
}
et la class InputStreamConsumerThread:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
 
public class InputStreamConsumerThread
extends Thread
{
 
private InputStream _in;
private OutputStream _out;
 
public InputStreamConsumerThread(ThreadGroup group, String name, InputStream in, OutputStream out)
{
super(group, name);
setDaemon(true);
if ( in == null )
{
throw new IllegalArgumentException("InputStream argument cannot be null");
}
_in = in;
_out = out;
}
 
public InputStreamConsumerThread(String name, InputStream in, OutputStream out)
{
this(null, name, in, out);
}
 
public void run()
{
byte[] buf = new byte[512];
int count = 0;
try
{
while ( (count = _in.read(buf)) != -1 )
{
if ( _out != null )
{
_out.write(buf, 0, count);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
il m'affiche l'erreur suivant:
sudo: no tty present and no askpass program specified

le probleme est au niveau de sudo.

aider moi svp.
merci.