Bonjour à tous,

j'ai créé une petite application sous Swing qui met permet d'envoyer des commande linux vers un serveur distant en SSH.
Pour cela j'ai utilisé l'API JSCH qui fonctionne assez bien pour ce que je fais pour l'instant.

En générale, les temps d'execution sont assez rapides quand j'envoie des commande (ls, cd,...)
Mais à un moment, j'utilise des commande DB2 via un fichier .sh qui fait un import de records dans une table. Donc la requête peut durer plus d'une miniutes suivant le nombre de records dans mon fichier.

L'ennui c'est que l'objet channel "écoute" l'activité de la console suivant un inputStream (de ce que j'ai trouvé) ou en définissant un temps donné.

Exemple :
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
 try {
 
            channel.connect();
            PrintStream ps = new PrintStream(ops, true);
            ps.println(command);
            // ps.close();
            InputStream in = channel.getInputStream();
            byte[] tmp = new byte[1024];
            long start = System.currentTimeMillis();
            long end = start + 2 * 1000; // 60 seconds * 1000 ms/sec
 
            while (System.currentTimeMillis() < end) {
                while (in.available() > 0) {
                    int i = in.read(tmp, 0, 1024);
                    if (i < 0) {
                        break;
                    }
                    System.out.print(new String(tmp, 0, i));
                }
                if (channel.isClosed()) {
                    System.out.println("exit-status: " + channel.getExitStatus());
                    break;
                }
                try {
                    Thread.sleep(1000);
                } catch (Exception ee) {
                }
            }
            // Thread.sleep(1000);
            // channel.disconnect();
        } catch (Exception e) {
        }
ou encore

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
 try {
            channel.connect();
            PrintStream ps = new PrintStream(ops, true);
            ps.println(command);
            InputStream in = channel.getInputStream();
            byte[] tmp = new byte[1024];
 
            while (true) {
                while (in.available() > 0) {
                    int i = in.read(tmp, 0, 1024);
                    if (i < 0) {
                        break;
                    }
                    System.out.print(new String(tmp, 0, i));//It is printing the response to console
                }
                System.out.println("done + Channelstatus "+ channel.isClosed());
 
                if (channel.isClosed()) {
                    System.out.println("exit-status: " + channel.getExitStatus());
                    break;
                }
                try {
                    Thread.sleep(1000);
                } catch (Exception ee) {
                }
            }
        }catch(JSchException e){
 
        }catch(IOException e){
 
        }
N'y a-t-il pas moyen de savoir si la commande est exécuté ou non et de sorte sortir du while ?

Merci d'avance pour votre aide