views:

65

answers:

3

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  A: 

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 $?

Alon
Thanks Alon! I tried, puts 'dir', but this just printed the string "dir". I wonder if I'm doing something wrong. Your second suggestion of, system("dir"), seemed to do the trick!
bporter
Glad it worked out for you, as for the first option its not ' its should be ` that is ASCII char 96
Alon
The first option now works, after changing ' to `. Thanks!
bporter
+1  A: 
task :build do
  command_line = "gcc ..."
  `#{command_line}`
end
Justice