Forum: Ruby execuate command problem

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.
Ef876fc6e1baa12cef2c381ea6feabbe?d=identicon&s=25 Martin Sharon (martinh)
on 2009-04-27 17:09
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!
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-04-27 17:13
(Received via mailing list)
2009/4/27 Martin Sharon <huangshuo.9@gmail.com>:
> ./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
Ef876fc6e1baa12cef2c381ea6feabbe?d=identicon&s=25 Martin Sharon (martinh)
on 2009-04-27 17:20
>
> 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
72c015d3601e275d5ee8a214e89cf03a?d=identicon&s=25 Alex Eiras (Guest)
on 2009-04-27 17:28
(Received via mailing list)
On Mon, Apr 27, 2009 at 5:20 PM, Martin Sharon
<huangshuo.9@gmail.com>wrote:

> > 17:12:42 bin$
> line= f.gets
>
>
line = f.gets.chomp to remove carriage return.

Cheers
Ef876fc6e1baa12cef2c381ea6feabbe?d=identicon&s=25 Martin Sharon (martinh)
on 2009-04-27 17:32
Alex Eiras wrote:
> On Mon, Apr 27, 2009 at 5:20 PM, Martin Sharon
> <huangshuo.9@gmail.com>wrote:
>
>> > 17:12:42 bin$
>> line= f.gets
>>
>>
> line = f.gets.chomp to remove carriage return.
>
> Cheers

...it works! thank you!
This topic is locked and can not be replied to.