Benjamin
Benjamin

Reputation: 561

Running cmd scripts from a ruby file?

Is there anyway to write commands to the command prompt in windows and execute directly from a ruby program?

I would use this as a one click installer for all the gems I wanted to install on the computer after installing ruby. I hope that it would save time when transferring my ruby files to a new computer. Or would be an easier way to get a non-ruby person set up very quickly with all the gems I thought them might need.

I am imagining something like Watir but for the Cmd rather than a browser.

EDIT

Thanks to

How can I then close the cmd window without closing the program for instance:

'notepad'

starts a cmd window and it also starts notepad but the cmd windows stays until the notepad is closed.

Upvotes: 0

Views: 460

Answers (1)

Hunter McMillen
Hunter McMillen

Reputation: 61515

Ruby will execute anything you put in backticks ` in your associated shell.

so if you type

test = `ipconfig`
puts test

test should now have stored in it the data from the cmd call ipconfig

EDIT

You can also use the System(..) call in Ruby to execute commands

Upvotes: 3

Related Questions