如何通过ssh在远程计算机上运行应用程序?如何通过ssh在远程计算机上运行应用程序?
我试着用JSCH,这种方式:
Properties props = new Properties();
props.put("StrictHostKeyChecking", "no");
String host = "111.111.11.111";
String user = "myuser";
String pwd = "mypass";
// int port = 22;
JSch jsch = new JSch();
Session session = jsch.getSession(user, host);
session.setConfig(props);
session.setPassword(pwd);
session.connect();
System.out.println(session.getServerVersion());
System.out.println("Conected!");
// String command = "ps -ef;date;hostname";
String command = "myapplication someFileAsParameter";
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
// channel.setInputStream(System.in);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
,我有这样的:
庆典:为MyApplication:找不到命令
当试图通过壳执行这个命令,作品精细。
不一定需要是JSCH,可以是任何东西。
这是否工作,如果你使用命令行ssh? 'ssh [email protected] myapplication someFileAsParameter' –
此外,它是否可以使用'ps'? –
当通过JSch登录时,您确定该命令在PATH中吗?我有一个模糊的感觉,这里可能有登录与非登录shell问题。 – qid