bon jour mais amis
j'ai un problem ! j'ai executer des commande cmd sur java class
le code ça marche bien mais i l y'a des Command qui me donné des erreur
voila le code de la class
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 import java.io.IOException; import java.io.PrintWriter; public class cmd1 { public static void main(String[] args) throws IOException, InterruptedException { String[] command = { "cmd", }; Process p = Runtime.getRuntime().exec(command); new Thread(new SyncPipe(p.getErrorStream(), System.err)).start(); new Thread(new SyncPipe(p.getInputStream(), System.out)).start(); PrintWriter stdin = new PrintWriter(p.getOutputStream()); stdin.println("dir c:\\ /A /Q"); //ca march bien stdin.println("cf login"); //ca march stdin.println("hakimguettaoui@gmail.com"); //ici si j'ai fait un login il me demander Email et mot de pass mais il me // donnée un pb stdin.println(""); // write any other commands you want here stdin.close(); int returnCode = p.waitFor(); System.out.println("Return code = " + returnCode); } }image de exécution
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 import java.io.InputStream; import java.io.OutputStream; class SyncPipe implements Runnable { public SyncPipe(InputStream istrm, OutputStream ostrm) { istrm_ = istrm; ostrm_ = ostrm; } public void run() { try { final byte[] buffer = new byte[1024]; for (int length = 0; (length = istrm_.read(buffer)) != -1; ) { ostrm_.write(buffer, 0, length); } } catch (Exception e) { e.printStackTrace(); } } private final OutputStream ostrm_; private final InputStream istrm_; }
voila mais amies elle me donnée ça
Email> Authenticating...
Credentials were rejected, please try again.
mais si j'ai utiliser cmd il foctionner normale il y'a pas des problem
si vous pl aide moi
Partager