c# – 从.NET执行Cygwin进程?

我正在尝试从.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无法找到库,因为它正在寻...

我正在尝试从.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”的潜在用法但听起来很脏,除非有很好的方法.

解决方法:

您是否正在使用混合本机Windows ruby??gems和Cygwin ruby???使用Cygwin ruby??gems似乎对我来说很好. (为什么你的Cygwin ruby??解释器显然在搜索带有Windows反斜杠的路径?).

或者,你试过run.exe吗?

C:\cygwin\bin\run.exe -p /starting/dir exe_to_run

这是man-page条目:

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进程?

基础教程推荐