配置cygwin/x以及自动设置DISPLAY (by Grant Zhou)

From: http://hi.baidu.com/grantzhou/blog/item/2edc1208bb8e33d163d98646.html

以下文章转自Grant的blog,有修改。原文标题为《配置cygwin/x以及自动设置DISPLAY》。

我们平时使用Hummingbird Exceed/X-manager其实只用到了它们的X server。而上述两个软件都不是免费软件。我们完全可以使用cygwin的X server来替代它们。使用cygwin的x-server优点:中文自动支持、鼠标支持特别是用emacs浏览code时的滚轮支持等等。下面是使用cygwin的X server的配置过程。

1 启动cygwin/x
有几种方法,参见: http://x.cygwin.com/docs/ug/using.html#using-starting
[color=red]startxwin.sh[/color]

1.1 直接运行windows bat 脚本
Edit C:\cygwin\usr\X11R6\bin\startxwin.bat [假设Cygwin的安装路径在C:\cygwin)

[quote]1) Remove
%RUN% xterm -e /usr/bin/bash -l
2) Add
%RUN% xhost +%RUN% xhost +
很奇怪,一定要加两遍才行;加一遍有时候就不生效。
3) get rid of the -silent-dup-error (Optional)
change the line below:
%RUN% XWin -multiwindow -clipboard -silent-dup-error
to
%RUN% XWin -multiwindow -clipboard[/quote]


1.2 用Cygwin bash脚本启动startx
每次启动会弹出一个必须保留弹出的xterm,如果退出这个xterm,X-Server自动退出。而且你必须运行xhost + 来允许远程服务器弹出窗口到你的机器上来。可以通过更改startxwin.sh脚本来启动x-server而无其他窗口弹出,并自动设置xhost:

[quote]1) 脚本位置
/usr/X11R6/bin/startxwin.sh
2) 屏蔽掉这几行
# Startup an xterm, using bash as the shell.xterm -e /usr/bin/bash -l &
3) 加上这几行来允许可以显示到你桌面上的服务器
# add XXX serverxhost + 135.123.123.123
[color=red]xhost + 135.123.123.124[/color]当然,加入 xhost + 则允许任何机器 连接到该 X server
4) 每次启动cygwin后,直接运行startxwin.sh 即可
任务栏会显示Cygwin/X server图标
5) 使用完毕后,记得在图标上点右键退出X-server
要不cygwin会等待它的关闭而长时间退不出。[/quote]

2 设置远程机器的 DISPLAY 参数
为了将远程机器(server)上运行的GUI程序显示到本地,你必须在远程机器上设置 DISPLAY, 我们在使用Exceed或者X-Manager时,startx会在启动Xterm时自动设置,其实我们也可以在.bashrc中加入自动设置DISPLAY的脚本:

[color=red]if [ -z "$DISPLAY" ]; then export DISPLAY=$(who am i | gawk 'BEGIN{FS="[()]"}{print $2}')":0.0"fi[/color]

另一种方法是采用SSH(来自公司内部新闻组的 Peter Fales):

Use "ssh" (either Cygwins's command line ssh, or another utility like PuTTY) to connect to the remote machine and enable "X forwarding." (This is a GUI option in PuTTY. For the command-line ssh, you put "ForwardX11=yes" in your $HOME/.ssh/config file, or use "ssh -X".) Not only is this more secure than using the PC's IP address, it automatically sets $DISPLAY for you.

3 Enjoy
经过如上设置,每次先启动Cygwin X Server 后,使用任意工具(如DOS的telnet命令,putty,securCRT等)telnet到服务器上后,直接运行任何图形界面的 X-windows 程序即可,如 emacs,tkcvs等。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值