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 :

[Runtime] Lancer un .bat


Sujet :

avec Java

  1. #1
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut [Runtime] Lancer un .bat
    Bonjour,

    je cherche de l'aide, je veux executer un ensemble de commade dos, j'ai met les commandes dans fichier .bat et je l'executer comme suite
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Runtime.getRuntime().exec(new String[] { "C:\\uninstall.bat" } );
    mais le code ne fonction pas, et si je execute le fichier .bat manulement les commades fonction ?

    Merci d'avance

  2. #2
    Membre chevronné
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Points : 2 197
    Points
    2 197
    Par défaut
    Il faut penser à faire une simple recherche avant de poster, le sujet est fréquemment abordé.
    Tu serais tombé sur : lancer un fichier.bat en java

  3. #3
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    voici le code que je teste :
    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
    public class GService {
     
    	public static void Gservices () {
     
    	 String name = "easytime-ws";
    	 String description = "Easytime";
     
    	 String path = new File("easytime-ws.properties").getAbsolutePath();
     
     
    	 System.out.println("pathURL = "+path);
     
     	 try {
     
     		  FileReader is; 
     		  is = new FileReader(path);
    		  Properties p = new Properties();
    		  p.load(is);
     
    		  name = p.getProperty("DisplayName");  
     
    		  description = p.getProperty("ServiceDiscription");
     
              System.out.print("lang = "+description);
     
              is.close();   
     	 }  
     
     
     	 catch (FileNotFoundException e1) {
     
    		e1.printStackTrace();
     
     
     	 } catch (IOException e1) {	
    		e1.printStackTrace();
    	}
     
     	try {  
     
     
     
     		  // String path1 = new File("easytime-ws.jar").getAbsolutePath();
     
     		   //String path3 = new File("Gservice/uninstall.bat").getAbsolutePath(); 
     
     		   Runtime.getRuntime().exec(new String[] { "Gservice/uninstall.bat" } );
     
     		   //Runtime.getRuntime().exec(" cmd.exe /c \"\"+path3+\"");
     
     		   // Runtime.getRuntime().exec("cmd.exe /c JavaService -install \"easytime-ws\" c:\\j2sdk\\jre\\bin\\service\\jvm.dll -XX\\:MaxPermSize\\=128m -Djava.class.path = "+path1+"  -err \"c:\\app\\err.txt\" -start calcul -auto -append -description \"description\"");
     
     
         	}
     	catch (Exception e4) { 
     
     
     		} 
     
     	finally {
     
    		}
     
    	}

  4. #4
    Membre chevronné
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Points : 2 197
    Points
    2 197
    Par défaut
    As-tu lu le lien que je t'ai indiqué? les paramètres de la méthode exec ne ressemblent pas du tout à ce que tu donnes.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Runtime.getRuntime().exec(
          "C:\\titi\\toto.bat", null,
          new File("C:\\titi\\"));

  5. #5
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    j'ai déjà testé le code mais ne marche pas aussi

  6. #6
    Membre chevronné
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Points : 2 197
    Points
    2 197
    Par défaut
    Quelle est l'erreur?

  7. #7
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    salut

    j'ai pas une erreur parfoit le Runtime execute le fichier .bat parfoit non, si je teste un fichier .exe ça marche toujours ? je ne sais pas ou est le problème ::

    Merci

  8. #8
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Salut,

    Citation Envoyé par empire.dev Voir le message
    je ne sais pas ou est le problème ::
    Tu ne traites pas les flux d'entrées/sorties...
    Tu dois soit les traiter (dans des threads séparés), soit les fermer (si tu veux les ignorer)

    Plus d'info :


    a++

  9. #9
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    Merci infiniment :

    j'arrive bien a lancer .exe mais le .bat ne fonction pas encore : voici mon code :
    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
    String path3 = new File("install.bat").getAbsolutePath(); 
     
     		  String[] cmd = { 
     
     				 "cmd.exe", "/C",
     
     				 path3 };
     
     
     				 try {
     				 Runtime r = Runtime.getRuntime();
     
     				 Process p = r.exec(cmd);
     
     				 p.waitFor();
     
     				 } catch (Exception e) {
     
     				 System.out.println("erreur d'execution " + cmd + e.toString());
     
     				 }

    S'il vous plait aider moi.

    Merci d'avance

Discussions similaires

  1. lancer un .bat et cacher la fenetre dos
    Par peppena dans le forum Scripts/Batch
    Réponses: 28
    Dernier message: 06/07/2019, 14h42
  2. [Runtime]lancer une application externe
    Par biozaxx dans le forum Général Java
    Réponses: 3
    Dernier message: 09/11/2005, 17h13
  3. [Système] lancer un .bat en PHP
    Par valal dans le forum Langage
    Réponses: 5
    Dernier message: 20/10/2005, 11h40
  4. [Système][Runtime]lancer une application externe
    Par mencaglia dans le forum API standards et tierces
    Réponses: 14
    Dernier message: 22/09/2005, 17h27
  5. [Système][Runtime] lancer une commade avec un PIP
    Par IVAGO dans le forum API standards et tierces
    Réponses: 18
    Dernier message: 19/08/2005, 19h49

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