如何在远程ubuntu系统中启动浏览器?

时间:2014-12-18 11:11:26

标签: java ubuntu ssh jsch

我正在运行两台Ubuntu 12.04计算机。机器A需要在机器B上启动浏览器(firefox或chrome),但它不需要它来查看浏览器窗口。它只需要启动浏览器并保留它。我使用JSch库(下面的代码片段)实现了它,但这是返回的消息 - 错误:未指定显示

作为解决方案,在机器B上,我将 DISPLAY 变量设置为 localhost:port ipAddress:port 其中 ipAddress 是它自己的IP地址,而端口是0或其他一些数字,如10但它没有帮助。

以下是机器A的作品。

ssh -X <machine B ipAddress>
$firefox 

我在Virtualbox上运行Windows 7作为主机和两个Ubuntu 12.04(一个32位另一个64位)虚拟机,带有桥接网络。

代码:

JSch jsch = new JSch();
Session session = jsch.getSession(user, ipAddress, 22);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();

ChannelExec channelExec = null;
channelExec = (ChannelExec)session.openChannel("exec");
String command = "firefox -p project001 http://www.google.com";
channelExec.setCommand(command);
String port  = command.substring(20, 21); // which is "1"
String display = ipAddress + ":" + port;
channelExec.setEnv("DISPLAY", display);
//channelExec.setXForwarding(false);

channelExec.setInputStream(null);
InputStream err = channelExec.getErrStream();
InputStream in = channelExec.getInputStream();

channelExec.connect();

有什么建议吗?非常感谢使用JSch或其他任何帮助。

更新:如果我更新命令以在后台运行firefox,它会运行,但我无法将其显示在浏览器窗口中。

0 个答案:

没有答案
相关问题