I'm new to Ruby, so this may be a pretty basic question.
I have a Windows batch file that I use all the time to interface with my source control system . The batch file issues various command-line commands supported by the source control system's command line interface (CLI).
I'd like to write a Ruby program that issues some of these commands. In general, how do you issue command-line commands from a Ruby program on Windows?
Thanks!
3 Answers 3
to run a system (command line) command in ruby wrap it with `
for example
puts `dir`
will run the cmd
window dir
command
if you need the return value (ERRORLEVEL
) you can use the system
command
for example system("dir")
which return a true
for success and false
for failure the ERRORLEVEL
value is stored at $?
2 Comments
task :build do
command_line = "gcc ..."
`#{command_line}`
end
Comments
http://rubyonwindows.blogspot.com/2007/05/automating-windows-shell-with-ruby.html
and for scripting: