简体   繁体   English

如何在cygwin中启动Windows GUI程序?

[英]how to start a windows GUI program in cygwin?

I have gVim installed in my Win7 and I am using cygwin a lot. 我在Win7中安装了gVim,而且我正在使用cygwin。

When I am in cygwin bashell I want to enter "vim aaa.c" and then let my Windows program gVim open aaa.c for me. 当我在cygwin bashell时,我想输入“vim aaa.c”,然后让我的Windows程序gVim为我打开aaa.c.

Would anyone tell me to do what configuration then this could work? 有人会告诉我做什么配置然后这可行吗?

Typing "notepad" directly in cygwin shell and pressing enter works. 直接在cygwin shell中键入“notepad”并按Enter键即可。 I know "notepad" can be found in Windows' system variable "path" so it works. 我知道“记事本”可以在Windows的系统变量“路径”中找到,所以它可以工作。 I have tried adding my gVim.exe's path to system variable "path" but it doesn't work. 我已经尝试将我的gVim.exe的路径添加到系统变量“path”但它不起作用。

PS: if you type "run notepad" in cygwin shell it also starts Windows notepad. PS:如果你在cygwin shell中输入“run notepad”,它也会启动Windows记事本。 But how to make my gVim recognized by cygwin just like 'notepad'? 但是如何让我的gVim被cygwin认可就像'记事本'一样? I don't want to type the full installation path to my gVim in cygwin shell every time. 我不想每次都在cygwin shell中输入我的gVim的完整安装路径。

Thanks! 谢谢!

The easiest solution is to add the following line in your .bashrc 最简单的解决方案是在.bashrc中添加以下行

alias vim="/cygdrive/c/Program\\ Files\\ \\(x86\\)/vim/vim73/gvim.exe"

when invoking vim do vim foo.txt & , the & ensures the process is run in the background so your shell is still usable before the process ends. 当调用vim do vim foo.txt &&确保进程在后台运行,因此在进程结束之前shell仍然可用。

if you do not want to type the & every time, do the following alias 如果您不想每次都输入& ,请执行以下别名

alias vim="cygstart /cygdrive/c/Program\\ Files\\ \\(x86\\)/vim/vim73/gvim.exe"

The best solution though is to install cygwin vim instead of using the windows version. 但最好的解决方案是安装cygwin vim而不是使用windows版本。 With the windows one, you will fight with the path conversion all the time. 有了一个窗口,你将一直与路径转换斗争。 Really you want it to work for all the followings: 真的,你希望它适用于以下所有方面:

vim ~/foo
vim /bar
vim $home/abc
vim /cygpath/c/def
vim "c:\ghi"

There are some complicated shell scripts which help ease the problem, but I have not come across any that does not have certain caveat. 有一些复杂的shell脚本可以帮助缓解问题,但我没有遇到任何没有一定警告的问题。

作为快速入侵,请尝试使用完整路径名,cygwin样式,例如/cygdrive/c/Program\\ Files/gVim/gVim.exe

For me, the following works: 对我来说,以下工作:

$ PATH=/cygdrive/c/Program\ Files\ \(x86\)/vim/vim73:$PATH
$ gvim

You can add to the PATH in your ~/.profile , but adding to the Windows PATH variable (via the Control Panel) should work, too. 您可以在~/.profile添加PATH,但添加到Windows PATH变量(通过控制面板)也应该有效。 (Just be sure to use the normal C:\\... notation then.) (请务必使用正常的C:\\...表示法。)

Hmmm, I'm slow. 嗯,我很慢。 On your windows machine, there is a Cygwin folder with a home folder and your username folder. 在您的Windows机器上,有一个Cygwin文件夹,其中包含一个home文件夹和您的username文件夹。 Just open the file explorer and edit it with windows gvim, then do the save and run it in bash. 只需打开文件资源管理器并使用windows gvim进行编辑,然后执行保存并在bash中运行它。 There is no need to make this a difficult problem. 没有必要使这成为一个难题。

我刚刚安装了Cygwin,当我检查了我的路径(echo $ PATH)时,我发现它基本上继承了路径中的任何窗口...所以如果你在你的Windows路径中有gvim你在Cygwin路径中拥有它...这意味着cygstart gvim将启动gvim ...非所需的hokey路径问题...我确信你可以通过命令行args并在后台运行它...

For me the command 'run' in cygwin works. 对我来说,cygwin中的'run'命令有效。 It's similar to the 'open' command in OSX cli. 它类似于OSX cli中的'open'命令。

This is how I utilize it in my .bash_aliases file 这就是我在.bash_aliases文件中使用它的方法

# Location of Programs in Win10 that are stored under
# Program Files (x86)
alias x86PF='cd "/cygdrive/c/Program Files (x86)"'

# Navigating to the location of Program Files (x86)
# then switching to the Notepad++ dir
# then calling 'notepad++.exe' with the run command.
# Note the use of the && to run multiple commands in one alias assignement


alias notepad++='x86PF && cd Notepad++ && run notepad++.exe'

Don't forget to source your .bashrc after you've modified your file with the aliases 在使用别名修改文件后,不要忘记使用.bashrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从桌面图标通过Cygwin启动带有GUI的GNU Octave? - How to start GNU Octave with GUI through Cygwin from a desktop icon? Cygwin:Windows上的Linux? 如何确保Windows创建的程序适用于Linux - Cygwin: Linux on Windows? How to ensure that program created in Windows works for Linux 是否可以通过ssh进入Windows(通过cygwin sshd)并在登录的Windows用户桌面上启动程序? - Is it possible to ssh into Windows (through a cygwin sshd) and start a program on a logged in Windows user's desktop? 如何在 Windows 中通过 Cygwin 安装和运行 Nmap 程序? - How to install and run the Nmap program through Cygwin in Windows? 如何使用 Windows 中的 python 脚本在 cygwin 中运行程序? - How to run program in cygwin using python script from windows? 如何在 Windows 上使用 Cygwin 编译和链接 OpenGL/GLFW 程序? - How to Compile and Link an OpenGL/GLFW Program with Cygwin on Windows? 用Cygwin构建的Windows GUI程序是否需要Cygwin? - Do Windows GUI programs built with Cygwin require Cygwin? 我如何从cygwin ssh运行win32 gui程序? - How can I run a win32 gui program from cygwin ssh? 如何为最终用户方便地启动Java GUI程序 - How to start Java GUI program conveniently for the end user 在 windows 终端中的 $USERPROFILE 中启动 Cygwin(预览版) - Start Cygwin in $USERPROFILE in windows terminal (preview)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM