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

标签 c# .net ruby process 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 无法定位库,因为它正在寻找一些 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 ruby​​gems 和 Cygwin ruby​​?使用 Cygwin ruby​​gems 似乎对我来说效果很好。 (为什么您的 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/

相关文章:

c# - 除了相应的 `foreign key Id` 之外,我还应该定义 `navigation property` 属性吗?

c# 如何将文本文件的行分成两等份,并在两个不同的列表框中显示

ruby-on-rails - Ruby on Rails : required parameters for model

css - 我需要一个 ruby​​ 中的 css 压缩器

c# - 在图表上显示 X 和 Y 值的数据点

c# - 当变量类型为 [int?] 时,为什么我必须在 C# 中强制转换为 (int?)

c# - 我究竟做错了什么? wcf 和 Entity Framework

c# - 如何从另一个类访问控件?

ruby - Nokogiri 如何以正确的间距从 HTML 中提取文本?

c# - 如何使用LINQ将List <Int32>中的所有元素选择到另一个List <Int32>中?