Running a Cygwin process from .NET?

I am trying to run Cygwin version of ruby.exe from a .NET application, but I am stuck.

c:\>"c:\cygwin\bin\ruby.exe" c:\test\ruby.rb /usr/bin/ruby: no such file to load -- ubygems (LoadError) 

As you can see, Ruby cannot find libraries because it is looking for some Linux-style paths.

Obviously, when I run ruby.exe from .NET, since it cannot find the libraries, it fails, as shown above.

If I do not load any library, it works fine:

 c:\>"c:\cygwin\bin\ruby.exe" -v ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] 

Initially, cygwin starts with this cygwin.bat

 chdir C:\cygwin\bin bash --login -i 

How can I get .NET to first go into a cygwin environment and then run ruby ​​in that environment?

  • I can not use Windows Ruby, I need cygwin ruby.
  • I know about the potential use of "bash" interactive driving, but that sounds dirty unless there is a good way to do it.
+4
source share
2 answers

Are you using, possibly mixing your own Windows rubigmas and Cygwin ruby? Using Cygwin rubygems seems to work fine for me. (Why does your Ruby Ruby interpreter seem to be looking for a path with Windows back braids?).

Have you tried run.exe as an alternative?

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

Here's the man page:

NAME

run - run programs with a hidden console window

SYNTAX

execute the command [-p path] [-wait]

runcommand [-p path] [-wait] arguments

DESCRIPTION

Windows programs are either GUI programs or console programs. when running console programs will either attach to an existing console or create a new one. GUI programs can never join a single one. It is not possible to connect to an existing console, but hide it if started as a GUI program.

run will do it for you. It works as an intermediate and starts the gram, but hides the console window.

With -p path, you can add the path to the PATH environment variable.

Issuing -wait as the first argument to the program will cause wait to end for the program, otherwise it returns immediately.

The second option is to create wrappers. If the named runcommand executable file (for example, runemacs), start will try to start the program (for example, Emacs).

Examples

run -p / usr / X11R6 / bin xterm

run emacs -wait runemacs -wait

run make -wait

+4
source

Why don't you run a non-interactive bash shell that launches ruby ​​from your .NET application? Sort of:

 bash --login -c <your-path-to-ruby> <your-library-to-load> 

Not sure what your file structure is, but for example

 bash --login -c /usr/bin/ruby ~/test/ruby.rb 

For more information, see - c using the bash page .

+3
source

All Articles