IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

exécutable en java


Sujet :

avec Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de nypahe
    Inscrit en
    Novembre 2006
    Messages
    174
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 174
    Par défaut exécutable en java
    voici un code qui est censé tourner, mais il a cette erreur que je ne comprends pas: error executing C:\glpsol --math antichaine.mod --output antichaine.txt

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    Public void tourner(){
    Runtime r = Runtime.getRuntime();
    		  Process p = null;
    		  String cmd[] = { "C:\\glpsol --math antichaine.mod --output antichaine.txt"};
    		  try {
    		      p = r.exec(cmd);
    		  } catch (Exception e) {
    		      System.out.println("error executing " + cmd[0]);
    		  }
     
    	}

  2. #2
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    tu dois séparer les différents paramètres de ta commande. Aussi, utiliser e.printStackTrace() est utile pour savoir quelle est l'erreur.

  3. #3
    Membre confirmé Avatar de nypahe
    Inscrit en
    Novembre 2006
    Messages
    174
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 174
    Par défaut
    voila les erreurs
    Cannot run program "C:\glpsol --math antichaine.mod \--output antichaine.txt": CreateProcess error=3, Le chemin d'accès spécifié est introuvable
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at Read_and_write.tourner(Read_and_write.java:104)
    at Read_and_write.main(Read_and_write.java:324)
    Caused by: java.io.IOException: CreateProcess error=3, Le chemin d'accès spécifié est introuvable
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 5 more

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 18
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Caused by: java.io.IOException: CreateProcess error=3, Le chemin d'accès spécifié est introuvable
    Il semblerait que ton programme glpsol ne se trouve pas à la racine du C:\
    Le plus simple pour vérifié que ta commande marche est de l'executer dans l'invite de commande.

  5. #5
    Membre Expert Avatar de Uther
    Homme Profil pro
    Tourneur Fraiseur
    Inscrit en
    Avril 2002
    Messages
    4 690
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Tourneur Fraiseur

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 690
    Par défaut
    Il est également bon de séparer le paramètres
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String cmd[] = { "C:\\glpsol", "--math", "antichaine.mod", "--output", "antichaine.txt"};

  6. #6
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Citation Envoyé par tchize_ Voir le message
    tu dois séparer les différents paramètres de ta commande.

  7. #7
    Membre confirmé Avatar de nypahe
    Inscrit en
    Novembre 2006
    Messages
    174
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 174
    Par défaut
    La commande, même avec les cotes, ne me donne pas resultat,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String cmd[] = { "C:\\glpsol", "--math", "antichaine.mod", "--output", "antichaine.txt"};
    c'est à dire generer le fichier antichaine.txt. Il ne présente pas d'erreur dans le code.
    Merci pour votre aide.
    Faut il changer la manière d'agencer les cotes?

    Juste pour préciser que : glpsol est un solveur qui se trouve avec le fichier amtichaine.mod dans le repertoire c:\
    et devrait me generer antichaine.txt

    Quand j'effectue cette operation manuellement ça fonctionne sans problème.

  8. #8
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    affiche nous ton nouveau code.

  9. #9
    Membre confirmé Avatar de nypahe
    Inscrit en
    Novembre 2006
    Messages
    174
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 174
    Par défaut
    la methode :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    private static void tourner() {
     
    		String cmd[] = { "C:\\glpsol", "--math", "antichaine.mod", "--output", "antichaine.txt" };
    		try {
     
    		Process process = Runtime.getRuntime().exec(cmd);
     
    		} catch (Exception e) {
    			e.printStackTrace();
     
    		}
     
    	}

  10. #10
    Membre confirmé Avatar de nypahe
    Inscrit en
    Novembre 2006
    Messages
    174
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 174
    Par défaut
    voici tout mon code.
    je l'appelle dans le 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
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    import java.io.*;
    import java.util.ArrayList;
     
     
    //import org.gnu.glpk;
     
    public class Read_and_write {
     
     
     
    	public static void Read() {
    		BufferedReader reader = null;
    		int compteur = 0;
     
    		final int nbLignesASauter = 15;
    		final int nbMax = 24;
    		try {
    			reader = new BufferedReader(new FileReader("C:\\herve.doc"));
    			String ligne;
     
    			while ((ligne = reader.readLine()) != null) {
    				compteur++;
    				if ((compteur > nbLignesASauter) && (compteur < nbMax)) {
     
    					// else {
    					String[] colonnes = ligne.split("\\s+");
    					for (int i = 0; i < colonnes.length; i++)
    					System.out.print(colonnes[i] + "\t ");
    					System.out.println("");
    				}
     
    			}
     
    		} catch (IOException ioe) {
    			ioe.printStackTrace();
    		} finally {
    			try {
    				if (reader != null)
    					reader.close();
    			} catch (IOException ioe) {
    				ioe.printStackTrace();
    			}
    		}
    	}
     
    	private static void tourner() {
     
    		String cmd[] = { "C:\\glpsol", "--math", "antichaine.mod", "--output", "antichaine.txt" };
    		try {
     
    		Process process = Runtime.getRuntime().exec(cmd);
     
    		} catch (Exception e) {
    			e.printStackTrace();
     
    		}
     
    	}
     
    	public static void main(String[] args) {
     
    		ArrayList<String> tableau = new ArrayList<String>();
     
    		// String tab[] = { "01111011","111","011", "111", "101", "110111",
    		// "15", "21", "22", "23",
    		// "24", "25", "31", "32", "33", "34", "41", "42", "43", "44",
    		// "45", "51", "52", "53", " 54", " 55" };
    		String[] tab = { "00001111111010110001"};
     
    		int p = 4;
     
    		for (int i = 0; i < tab.length; i++) {
    			tableau.add(tab[i]);
    		}
    		for (String elt : tableau) {
    			String chemin;
    			chemin = "C:" + File.separator + "antichaine.mod";
    			File fichier = new File(chemin);
    			try {
    				FileWriter writer = new FileWriter(fichier);
    				BufferedWriter output = new BufferedWriter(writer);
     
    				try {
     
     
    					String vec = elt;
    					output.write("# Decision Variables\n");
    					output.write("var lambda, >=0;\n");
    					output.write("var w{1.." + p + "}, >=0;\n\n");
     
    					output.write("#Objective function\n");
    					//output.write("printf\"Fmin: %d\", " + vec + "; \n");
    					output.write("minimize obj: lambda;\n\n");
    					output.write("#Constraints\n");
     
    					int compt = 0;
    					int cas = 0;
    					int po = 0;
     
    					int nb = (vec.length() / p);
    					while (nb != 0) {
     
    						String result = "init";
    						int deb = (po * p);
    						po++;
    						int fin = (po * p);
    						String v = vec.substring(deb, fin);
     
    						int tailleV = v.length();
    						int tail = tailleV;
    						char charV;
    						compt = 0;
    						output.write("s.t. const" + cas + ": ");
    						cas++;
    						while (tailleV != 0) {
     
    							charV = v.charAt(--tailleV);
    							String sV = Character.toString(charV);
    							int iElt = Integer.parseInt(sV);
     
    							compt++;
    							String t = new String("w[");
    							String a = "+";
    							String b = "]";
     
    							if (compt <= tail) {
    								if ((iElt == 1) && (result == "init")) {
    									result = t + compt + b;
    									output.write(result);
    								} else if ((iElt == 1) && (result != "init")) {
    									output.write(a);
    									result = t + compt + b;
    									output.write(result);
    								}
    							}
    						}
    						if (result != "init") {
    							output.write(" >= lambda;\n");
    						} else {
    							output.write("lambda >= 0;\n");
    						}
    						nb--;
    					}
     
     
    					output.write("s.t. const" + 19 + ":\tsum{i in 1.." + p
    							+ "} w[i]= 1;\n\n");
     
    					output.write("#Solving this model\n");
    					output.write("solve;\n\n");
    					output.write("#Printing the optimal values:\n");
    					output.write("printf\"lambda: %f\", lambda; \n");
    					output.write("for {i in 1.." + p + "}\n");
    					output.write("{\n");
    					output.write("printf\"\t w[%d]: %f\", i, w[i]; \n");
    					output.write("}\n");
    					output.write("end;\n");
     
    				} finally {
    					output.close();
    					writer.close();
    				}
    			} catch (Exception e) {
    				System.out.println("Impossible de creer le fichier");
    				e.printStackTrace();
    			}
     
    			tourner();
     
    		}
    	}
     
    }

  11. #11
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Quelle est l'erreur affichée dans la console?

  12. #12
    Membre confirmé Avatar de nypahe
    Inscrit en
    Novembre 2006
    Messages
    174
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 174
    Par défaut
    La console n'affiche pas d'erreur, et le programme tourne. il n'y a pas d'exception.
    Mais quand je me rends dans mon repertoire, je ne trouve pas fichier .txt

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème avec mon premier exécutable en java
    Par Icefire dans le forum Débuter avec Java
    Réponses: 9
    Dernier message: 25/04/2008, 09h42
  2. Problème d'exécution de Java
    Par djakaridja dans le forum Débuter avec Java
    Réponses: 23
    Dernier message: 10/04/2008, 09h59
  3. exécution appli java sur un pda
    Par air75 dans le forum Développement Mobile en Java
    Réponses: 10
    Dernier message: 15/11/2007, 13h44
  4. [Maven2] Exécution Commande Java
    Par Deaf dans le forum Maven
    Réponses: 3
    Dernier message: 24/03/2007, 09h58
  5. [Run]Exécution de java.exe au lieu de javaw.exe par Eclipse
    Par newfsch dans le forum Eclipse Java
    Réponses: 5
    Dernier message: 24/11/2005, 12h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo