# How to run a command line command

**URL:** <https://www.ruby-forum.com/t/how-to-run-a-command-line-command/87755>\
**Category:** Ruby\
**Created:** [March 5, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/how-to-run-a-command-line-command/87755 "2007-03-05T19:23:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [March 5, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/how-to-run-a-command-line-command/87755/1 "2007-03-05T19:23:31Z")

</div>

lo there all  
i have an app that i want to launch an application from.  
i use linux with a bash shell. If i want to launch a program from my  
terminal, i use  
./myprogram  
or /home/myuser/myprogram

how could i do something like this from a ruby script ?

thanks  
sk

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [March 5, 2007, 8:55pm UTC](https://www.ruby-forum.com/t/how-to-run-a-command-line-command/87755/2 "2007-03-05T20:55:46Z")

</div>

On Mar 5, 1:41 pm, “Dale M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Note: those are back ticks by the way.

cool enough, works great, thanks  
sk

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [March 6, 2007, 3:55am UTC](https://www.ruby-forum.com/t/how-to-run-a-command-line-command/87755/3 "2007-03-06T03:55:33Z")

</div>

also %x(vim somefile)

“nephish” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
???:removed\_email\_address@domain.invalid…

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [March 5, 2007, 8:45pm UTC](https://www.ruby-forum.com/t/how-to-run-a-command-line-command/87755/4 "2007-03-05T20:45:43Z")

</div>

On Mar 5, 12:22 pm, “shawn bright” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> sk  
> There are a number of ways to accomplish this:

```
 system( 'vim somefile' )

```

or

```
 `vim somefile`

```

Note: those are back ticks by the way.

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [March 6, 2007, 8:10am UTC](https://www.ruby-forum.com/t/how-to-run-a-command-line-command/87755/5 "2007-03-06T08:10:40Z")

</div>

Dale M. wrote:

> On Mar 5, 12:22 pm, “shawn bright” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > sk  
> > There are a number of ways to accomplish this:
> 
> ```
> system( 'vim somefile' )
> 
> ```
> 
> or
> 
> ```
> `vim somefile`
> 
> ```
> 
> Note: those are back ticks by the way.

I avoid the latter unless I need the output generated by the command. By  
doing so, I bypass a bunch of needless processing (capture command’s  
STDOUT to a newly allocated string buffer), or so I think. Does anyone  
know for sure?

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [March 6, 2007, 4:00am UTC](https://www.ruby-forum.com/t/how-to-run-a-command-line-command/87755/6 "2007-03-06T04:00:34Z")

</div>

On Tue, Mar 06, 2007 at 11:55:09AM +0900, Wang Dong wrote:

> also %x(vim somefile)

I wonder how that one escaped my attention. Thanks for mentioning it.

How does it work? Like ``, or system(), or . . . what?
