Java "exit value was non-zero"

Ben Coverflag Messages postés 17 Date d'inscription dimanche 29 mai 2005 Statut Membre Dernière intervention 20 novembre 2005 - 13 juin 2005 à 18:38
cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 - 13 juin 2005 à 21:26
Bonjour,

j'ai programmé en Java une interface qui me permet de lancer une requête sur un terminal. Ceci marche très bien avec ls ou pwd par exemple.
Or j'ai créé un annuaire ldap que je lance en étant "root". Je lance des requêtes en étant "root" sur mon terminal pour manipuler mon annuaire.
Mais lorsque je veux lancer ces requêtes à partir de l'interface en java ça ne marche pas et ça lance une interruption qui affiche "exit value non-zero".

Est-ce que vous auriez la solution pour que ça marche?

Si vous voulez voir mon code pour être à même de me répondre n'hésitez pas à me le demander je vous l'envoie sur votre messagerie du site (ou autre).

Merci
Ben.

3 réponses

cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 8
13 juin 2005 à 19:06
Salut,



heu tu peux nous filer ton code PHP ici dans le forum, et pour ton code JAVA le forum JAVA pourra répondre à tes questions.



a +

<hr size="2" width="100%">




<li>Entraide, dépannage et vulgarisation informatique: Mon site de vulgarisation informatique</li>
0
Ben Coverflag Messages postés 17 Date d'inscription dimanche 29 mai 2005 Statut Membre Dernière intervention 20 novembre 2005
13 juin 2005 à 21:13
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/ 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/ 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();


}
}
0
cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 8
13 juin 2005 à 21:26
http://www.javafr.com/Default.aspx

<hr size="2" width="100%">




<li>Entraide, dépannage et vulgarisation informatique: Mon site de vulgarisation informatique</li>
0
Rejoignez-nous