error messages from bash aren't captured by ruby interpreter

B

Bruno Sousa

Hi everyone,
How can I write a ruby script in order to capture error messagens from
bash commands?

if I do this:
out = `rm /var/mail/teste2`

Errors like "rm: cannot remove `/var/mail/teste2': No such file or
directory" won't be stored in "out" string.

How can I do that?

regards
 
B

Brian Candler

Bruno said:
out = `rm /var/mail/teste2`

Errors like "rm: cannot remove `/var/mail/teste2': No such file or
directory" won't be stored in "out" string.

How can I do that?

out = `rm /var/mail/teste2 2>&1`

Otherwise look at open3 in the stdlib, if you want to get stdout and
stderr separately.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top