Tout fonctionne bien sur la ligne de commande, mais quand je traduis ce que je veux en Java, le processus de réception ne reçoit jamais rien sur stdin.Comment écrire en Java à stdin de ssh?
Voici ce que j'ai:
private void deployWarFile(File warFile, String instanceId) throws IOException, InterruptedException {
Runtime runtime = Runtime.getRuntime();
// FIXME(nyap): Use Jsch.
Process deployWarFile = runtime.exec(new String[]{
"ssh",
"gateway",
"/path/to/count-the-bytes"});
OutputStream deployWarFileStdin = deployWarFile.getOutputStream();
InputStream deployWarFileStdout = new BufferedInputStream(deployWarFile.getInputStream());
InputStream warFileInputStream = new FileInputStream(warFile);
IOUtils.copy(warFileInputStream, deployWarFileStdin);
IOUtils.copy(deployWarFileStdout, System.out);
warFileInputStream.close();
deployWarFileStdout.close();
deployWarFileStdin.close();
int status = deployWarFile.waitFor();
System.out.println("************ Deployed with status " + status + " file handles. ************");
}
Le script 'count-the-octets' est tout simplement:
#!/bin/bash
echo "************ counting stdin bytes ************"
wc -c
echo "************ counted stdin bytes ************"
La sortie indique que la fonction est suspendue à la ligne 'wc -c' - il n'atteint jamais la ligne 'counted stdin bytes'.
Que se passe-t-il? Serait-il utile d'utiliser Jsch?
Lorsque vous utilisez IOCopy, quelle valeur est retournée? – Snicolas
J'ai changé le code pour utiliser copyLarge(); il a renvoyé 30054046. –