他のマシンにsshを作るこの方法があるとします。そのマシンの端末からの出力をホストマシンに戻すにはどうすればいいですか?java runtim.execをsshに使用する場合、そのリモートマシンのコンソール出力を取得するにはどうすればよいですか?
public void getSSHreply()
{
Process p;
// Set up the arguments for ProcessBuilder
String[] cmd =
{
"/usr/bin/ssh",
"someRemoteMachine", //This machine will authenticate with keys, hence no pw needed
"./myprog",
};
try
{
p = Runtime.getRuntime().exec(cmd);
//How would I redirect stdout back to host machine?
StringBuffer s = new StringBuffer();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while (input.readLine() != null)
{
s.append(input.readLine() + "\n");
}
System.out.println(s.toString());
}
catch (IOException e)
{
System.err.println("Failed to read & or start ");
}
}
これに少し入ることができますか?これは前にやりたかったことです。 –
私はパスワードを必要としません。私は鍵で認証します。 – stackoverflow