Have you looked at the Ruby shell library? It is part of the standard installation. On Linux you'll find it at /usr/lib/ruby/1.8/shell
You can look up the Shell class and its methods at http://www.ruby-doc.org/core/
You can do anything you'd from the command line and pass values back and forth. You can write your own classes and put the file in the RAILS_ROOT/lib dir.
I am using it to do some file format conversions. To see how shell is used you can look into the doc_convert library to see how shell is used. That's what I did. http://raa.ruby-lang.org/project/doc_convert/
Hope this helps,
bakki