Forum: Ruby backtick vs. system()

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2007-06-18 19:21
(Received via mailing list)
Hi,

I have problems with the difference between the system() call and a
backtick call `command`.

Everything work fine until I try to redirect the output of the script.

Ex.
puts `ls`
system('ls')

A normal run is fine.
The redirected version with   test.rb >test.log 2>&1    stops with
"bad file descriptor".
If you try the command independent, you will see that system() causes
the problem.
Any hints?

I used system, due I can see the output during the run.
With puts `ls` it will be only visible at the end.

Thanks
   Peter
Jeremy T. (Guest)
on 2007-06-18 19:49
(Received via mailing list)
Try using IO#popen instead.

--
Jeremy T.
removed_email_address@domain.invalid
This topic is locked and can not be replied to.