Search code examples
ruby-on-railsrubywindowsjrubyjrubyonrails

Windows commands in ruby


How do I run a Windows command in an Ruby app?

I am trying to run something like:

output = `cd #{RAILS_ROOT}/lib && java HelloWorld #{param1} #{param2}`

I print the result of the line above and paste it to a command prompt in Windows and it works just fine. However, when i run app and hit this code, output is blank rather than have a string I get back from HellowWorld. In HelloWorld I do a System.out.print("helloworld")

The following:

output = `cmd.exe /C dir`
puts "OUTPUT #{output}"

Returns:

OUTPUT


Solution

  • Issue in JRuby 1.5.3 fixed in JRuby 1.5.5: http://www.jruby.org/2010/11/10/jruby-1-5-5.html