1

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!

asked Jan 16, 2010 at 19:30

3 Answers 3

4

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

answered Jan 16, 2010 at 19:35

2 Comments

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!
Glad it worked out for you, as for the first option its not ' its should be ` that is ASCII char 96
1
task :build do
 command_line = "gcc ..."
 `#{command_line}`
end
answered Jan 16, 2010 at 19:36

Comments

0

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.