Forum: Ruby Re: system() help

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gennady B. (Guest)
on 2006-02-21 22:46
(Received via mailing list)
system() does not do anyting with stdout or stdin, and it returns true
or false depending on the command exit code. If you want to collect the
program's stdin, the easiest way would be to use backquotes:

@myresult = `ls`

If you want to collect stderr as well, depending on you system shell you
can do something like:

@myresult = `command_writing_to_stderr 2>&1`

Or you can deal with forking and exec-ing a command explicitelly, using
pipe() and redirecting stdout/stderr anyway you like (you may also want
to take a look at popen()).

This topic is locked and can not be replied to.