开发者

Running cmd scripts from a ruby file?

开发者 https://www.devze.com 2023-03-28 16:14 出处:网络
Is there anyway to write commands to the command prompt in windows and execute directly from aruby program?

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 开发者_Go百科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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消