If you're on Mac OS or Linux, you can use standard redirection and a simple shell call if you want to capture the STDOUT and STDERR to a variable in your script:
asdf = `ls foo 2>&1`
asdf # => "ls: foo: No such file or directory\n"
2>&1
simply redirects STDERR in the command output to STDOUT, which is captured when the program runs.
If you want to redirect both STDOUT and STDERR to the same file for later, use:
`ls foo > output.log 2>&1`
The STDOUT has to be redirected before &2>1
will take effect, but that will capture both.
For more information see the "Redirect" section of man sh
.