Section 14.1. Running External Programs

Chapter 14. Scripting and System Administration

Thus spake the master programmer: "Though a program be but three lines long, someday it will have to be maintained."

Geoffrey James, The Tao of Programming

Programmers often need to "glue" programs together with little scripts that talk to the operating system at a fairly high level and run external programs. This is especially true in the UNIX world, which daily relies on shell scripts for countless tasks.

Ruby is not always a convenient glue language because it is more general-purpose than that. But in the long run, anything that can be done in bash (or the others) can also be done in Ruby.

In many cases, you might just as well use one of the more traditional languages for this purpose. The advantage that Ruby has, of course, is that it really is a general-purpose language, full-featured, and truly object-oriented. On the theory that people might want to use Ruby to talk to the OS at this level, we present here a few tricks that might prove useful.

This chapter was difficult to organize. Much of the functionality could logically be grouped in different ways. If you don't find what you are looking for in the expected place, scan the rest of the chapter also.

In addition, much of what could be covered here is actually dealt with in other chapters entirely. Refer in particular to Chapter 10, "I/O and Data Storage," which covers file I/O and attributes of files; these features are frequently used in scripts of the kind discussed in the present chapter.

The Ruby Way(c) Solutions and Techniques in Ruby Programming
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2004
Pages: 269
Authors: Hal Fulton

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: