# Execuate command problem

**URL:** <https://www.ruby-forum.com/t/execuate-command-problem/166589>\
**Category:** Ruby\
**Created:** [April 27, 2009, 5:09pm UTC](https://www.ruby-forum.com/t/execuate-command-problem/166589 "2009-04-27T17:09:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [April 27, 2009, 5:09pm UTC](https://www.ruby-forum.com/t/execuate-command-problem/166589/1 "2009-04-27T17:09:53Z")

</div>

I want to execute a shell command in ruby, like this:

line = “tokyo paris london”  
par = “23 23 11 43”  
execute = “./comp #{line} #{par}”  
puts execute

but the command executed is

./comp tokyo paris london  
23 23 11 43

There is an “enter” there, how can I execute:

./comp tokyo paris london 23 23 11 43

without line changing?

thanks!

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [April 27, 2009, 5:13pm UTC](https://www.ruby-forum.com/t/execuate-command-problem/166589/2 "2009-04-27T17:13:55Z")

</div>

2009/4/27 Martin S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ./comp tokyo paris london  
> 23 23 11 43
> 
> There is an “enter” there, how can I execute:
> 
> ./comp tokyo paris london 23 23 11 43
> 
> without line changing?

Works for me

17:03:46 bin$ ruby \<\<XX

> line = “tokyo paris london”  
> par = “23 23 11 43”  
> execute = “./comp #{line} #{par}”  
> puts execute  
> XX  
> ./comp tokyo paris london 23 23 11 43  
> 17:12:42 bin$

You must have been doing something differently than posted.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [April 27, 2009, 5:20pm UTC](https://www.ruby-forum.com/t/execuate-command-problem/166589/3 "2009-04-27T17:20:49Z")

</div>

> Works for me
> 
> 17:03:46 bin$ ruby \<\<XX
> 
> > line = “tokyo paris london”  
> > par = “23 23 11 43”  
> > execute = “./comp #{line} #{par}”  
> > puts execute  
> > XX  
> > ./comp tokyo paris london 23 23 11 43  
> > 17:12:42 bin$
> 
> You must have been doing something differently than posted.
> 
> Kind regards
> 
> robert

Oh, I think the only difference is in my program

f=File.open(ARGV[0], ‘r’)  
line= f.gets

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [April 27, 2009, 5:28pm UTC](https://www.ruby-forum.com/t/execuate-command-problem/166589/4 "2009-04-27T17:28:35Z")

</div>

On Mon, Apr 27, 2009 at 5:20 PM, Martin S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > 17:12:42 bin$  
> > line= f.gets

line = f.gets.chomp to remove carriage return.

Cheers

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [April 27, 2009, 5:32pm UTC](https://www.ruby-forum.com/t/execuate-command-problem/166589/5 "2009-04-27T17:32:52Z")

</div>

Alex Eiras wrote:

> On Mon, Apr 27, 2009 at 5:20 PM, Martin S.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:
> 
> > > 17:12:42 bin$  
> > > line= f.gets
> 
> line = f.gets.chomp to remove carriage return.
> 
> Cheers

…it works! thank you!
