在命令行中一切正常,但是當我將所需內容翻譯成Java時,接收過程從不會在stdin上獲取任何內容。如何用Java寫入ssh的stdin?
這是我有:
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. ************");
}
腳本「計數的字節」很簡單:
#!/bin/bash
echo "************ counting stdin bytes ************"
wc -c
echo "************ counted stdin bytes ************"
輸出指示功能,在「廁所-c」線掛 - 它永遠不會進入「統計stdin字節」行。
發生了什麼事?會使用Jsch幫助嗎?
當您使用IOCopy時,返回哪個值? – Snicolas
我更改了代碼以使用copyLarge();它返回30054046. –