Salut, je n'ai pas de code PHP. Je vous mets mon code Java, quand même. Tu peux me dire où se trouve le forum Java?
Merci
import java.lang.String;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.ArrayList;
public class Identification extends JFrame implements ActionListener{
//déclaration du contenu de la fenetre
JTextField user = new JTextField(20);
JPasswordField password = new JPasswordField(20);
JTextField institution = new JTextField(20);
JButton ok = new JButton("Ok");
JButton annuler = new JButton("Annuler");
JLabel userlab = new JLabel("user");
JLabel passwordlab = new JLabel("mot de passe");
JLabel institutionlab = new JLabel("institution");
//il faut creer un conteneur pour mettre tout le reste dedans
JPanel pane = new JPanel();
//constructeur
public Identification(){
super("Identification");
setSize(250, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//prévient le programme que les boutons peuvent emettre des actions...
ok.addActionListener(this);
annuler.addActionListener(this);
//ajout des éléments de la fenetre dans un conteneur
pane.add(userlab);
pane.add(user);
pane.add(institutionlab);
pane.add(institution);
pane.add(passwordlab);
pane.add(password);
pane.add(ok);
pane.add(annuler);
add(pane);
//rend le tout visible
setVisible(true);
}
//gestion des actions (ce qu'il y a dans l'interface "ActionListener"
public void actionPerformed(ActionEvent event) {
//recupère l'objet qui a émis l'action
Object source = event.getSource();
if (source == ok){
//ici commence les actions effectuées après le clic sur "ok"
System.out.println("user: " + user.getText());
System.out.println("institution: " + institution.getText());
System.out.println("password: " + password.getText());
user.setText("");
institution.setText("");
password.setText("");
//ce qui ne passe pas:
//shellCom("/usr/local/ldap/libexec/slapd -d 5 -h ldap://:9009/ -f /usr/local/ldap/etc/openldap/slapd.conf");
shellCom("ls");
//ce qui ne passe pas:
//shellCom("/usr/local/ldap/bin/ldapcompare -x -w secret -H ldap://:9009/ \"cn=Toto,ou=AAA,o=INT,c=fr\" userPassword: motdepasse");
}
//Ici pour annuler
else {System.out.println("j'ai annule hahaha");}
}
public static String[] runCommand(String cmd)
throws IOException {
// set up list to capture command output lines
ArrayList list = new ArrayList();
// start command running
Process proc = Runtime.getRuntime().exec(cmd);
// get command's output stream and
// put a buffered reader input stream on in
InputStream istr = proc.getInputStream();
BufferedReader br =
new BufferedReader(new InputStreamReader(istr));
// read output lines from command
String str;
while ((str = br.readLine()) != null)
list.add(str);
// wait for command to terminate
try {
proc.waitFor();
}
catch (InterruptedException e) {
System.err.println("process was interrupted");
}
// check its exit value
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
// close stream
br.close();
// return list of strings to caller
return (String[])list.toArray(new String[0]);
}
public void shellCom(String commande){
try {
// run a command
String outlist[] = runCommand(commande);
//des tests quelconques:
//if (outlist[0].equals("/home/PI20/Interface")) System.out.println("affichage ok");
//else System.out.println("perdu");
// display its output
for (int i = 0; i < outlist.length; i++)
System.out.println(outlist[i]);
}
catch (IOException e) {
System.err.println(e);
}
}
public static void main (String[] arguments) {
Identification id = new Identification();
}
}