Search code examples
rubymsysgit

ruby script with command spawns a DOS shell instead of a msysgit one


I've installed the latest Git Bash (msysgit). If I create a simple ruby file named test.rb with the following content:

#!/usr/bin/env ruby

puts `dir`
puts `ls -al`

Running ruby test.rb will print the directory on the first puts but fail to find ls on the second puts. It is obviously spawning a DOS shell instead of a msysgit shell.

How can I specify that child processes should run under a msysgit shell?

Also, the child shell should inherit the environment variables (specially PATH) from the calling shell.


Solution

  • The answer as of writing is that it isn't possible. A spawn process in msysgit is a CMD process. We can however make the CMD process call a ruby script to work around this limitation.