Bonjour,
J'ai un problème avec l'exécution des commandes à distance
En faite lorsque je lance une commande là où il existe une variable d'environnement ça me renvoie le code erreur 127
exemple
si j'appelle cette méthode avec executeCommande("echo $VARIABLE")
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 public int executeCommande(String commande) throws IOException , JSchException{ ((ChannelExec)channel).setCommand(commande + "\n"); InputStream stdout = channel.getInputStream(); BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); System.out.println("Execute commande Line :[ " +commande +"]" ); InputStream sterro = channel.getExtInputStream(); BufferedReader stderrorReader = new BufferedReader(new InputStreamReader(stdout)); channel.setOutputStream(System.out); channel.connect(); while(stdoutReader.read() != -1){ System.out.println(stdoutReader.readLine()); } while(stderrorReader.read() != -1){ System.out.println(stderrorReader.readLine()); } //Récupération du code de sortie int exitCode = -1; while(exitCode == -1){ try{ Thread.sleep(2); }catch (Exception e) { } exitCode = channel.getExitStatus(); } return exitCode; }
ça renvoie 0 mais $VARIABLE c'est toujours null
Partager