# Backtick vs. system()

**URL:** <https://www.ruby-forum.com/t/backtick-vs-system/107152>\
**Category:** Ruby\
**Created:** [June 18, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/backtick-vs-system/107152 "2007-06-18T17:21:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 18, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/backtick-vs-system/107152/1 "2007-06-18T17:21:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 18, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/backtick-vs-system/107152/2 "2007-06-18T17:49:26Z")

</div>

Try using IO#popen instead.

–  
Jeremy T.  
removed\_email\_address@domain.invalid
