我正在尝试从 .NET 应用程序启动 Cygwin 版本的 ruby.exe,但我卡住了。
c:\>"c:\cygwin\bin\ruby.exe" c:\test\ruby.rb
/usr/bin/ruby: no such file to load -- ubygems (LoadError)
如您所见,Ruby 无法定位库,因为它正在寻找一些 Linux 风格的路径。
显然,当我从 .NET 运行 ruby.exe 时,因为它找不到库,所以它会像上面那样失败。
如果我不加载任何库,它工作正常:
c:\>"c:\cygwin\bin\ruby.exe" -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
原来cygwin是从这个cygwin.bat开始的
chdir C:\cygwin\bin
bash --login -i
如何让 .NET 首先进入 cygwin 环境,然后在该环境中执行 ruby?
- 我不会使用 Windows Ruby,我需要 cygwin ruby。
- 我知道交互式驱动“bash”的潜在用途,但这听起来很脏,除非有好的方法。
最佳答案
您是否混合使用 native Windows rubygems 和 Cygwin ruby?使用 Cygwin rubygems 似乎对我来说效果很好。 (为什么您的 Cygwin ruby 解释器显然在搜索其中包含 Windows 反斜杠的路径?)。
或者,您是否尝试过 run.exe
?
C:\cygwin\bin\run.exe -p /starting/dir exe_to_run
这是手册页条目:
NAME
run - start programs with hidden console window
SYNOPSIS
run [ -p path ] command [ -wait ] arguments
runcommand [ -p path ] [ -wait ] arguments
DESCRIPTION
Windows programs are either GUI programs or console programs. When started console programs will either attach to an existing console or create a new one. GUI programs can never attach to an exiting con- sole. There is no way to attach to an existing console but hide it if started as GUI program.
run will do this for you. It works as intermediate and starts a pro- gram but makes the console window hidden.
With -p path you can add path to the PATH environment variable.
Issuing -wait as first program argument will make run wait for program completition, otherwise it returns immediately.
The second variant is for creating wrappers. If the executable is named runcommand (eg runemacs), run will try to start the program (eg emacs).
EXAMPLES
run -p /usr/X11R6/bin xterm
run emacs -wait runemacs -wait
run make -wait
关于c# - 从 .NET 执行 Cygwin 进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/595600/