# Re: Execute shell command from Rails

**URL:** <https://www.ruby-forum.com/t/re-execute-shell-command-from-rails/83088>\
**Category:** Rails\
**Created:** [January 23, 2007, 4:19pm UTC](https://www.ruby-forum.com/t/re-execute-shell-command-from-rails/83088 "2007-01-23T16:19:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![piet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a9adbd/32.png) [@piet](https://www.ruby-forum.com/u/piet)\
**Post date:** [January 23, 2007, 4:19pm UTC](https://www.ruby-forum.com/t/re-execute-shell-command-from-rails/83088/1 "2007-01-23T16:19:46Z")

</div>

Hi Chuong,

I’ve used ‘open3’  
[http://www.ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html) repeatedly  
with succes.  
(used open3 because I needed stdout and stderr)

Piet.

* * *

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Chuong Huynh  
Sent: dinsdag 23 januari 2007 11:19  
To: removed\_email\_address@domain.invalid  
Subject: [Rails] Execute shell command from Rails

Hi all,

Can anyone tell what is the way to execute OS shell command from  
within Rails programs? I tried to use “exec” but it terminate the  
console (which run “ruby script/server” originally).

Thank you very much.

- Chuong

---

<div class="post-metadata">

**Author:** ![piet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a9adbd/32.png) [@piet](https://www.ruby-forum.com/u/piet)\
**Post date:** [January 23, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/re-execute-shell-command-from-rails/83088/2 "2007-01-23T17:47:16Z")

</div>

%x{shellcommand}

e.g.

%x{ls -l /}

2007/1/23, Piet H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![piet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a9adbd/32.png) [@piet](https://www.ruby-forum.com/u/piet)\
**Post date:** [January 23, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/re-execute-shell-command-from-rails/83088/3 "2007-01-23T18:11:27Z")

</div>

Hi,

Thank you for the info. I’ve found out also Kernel.system, IO.popen. I  
will  
try them all.

- Chuong
