[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

exec with string in variables?

chris

4/17/2007 2:53:00 PM

Hi,

i have something like this and more in perl and would transform it to
ruby.
First i changed system to exec and than the points to plus , but the
strings which are in the scalar's seems
not be applied in the exec call , perhaps some special needs with
quoting!?


:perl
foreach $line(@methoden) {
system("$exe_path" . "dti.exe -qb -t -e$line $dom_file
$train_file $modell_string" . "$line" . ".dti");
.................
}

:ruby

methoden.each do |line|
exec("exe_path + dti.exe -qb -t -eline dom_file train_file
modell_string + line + .dti")
..............
end

many thanks christian

2 Answers

Chris Hulan

4/17/2007 3:19:00 PM

0

On Apr 17, 10:53 am, Christian <o...@web.de> wrote:
> Hi,
>
> i have something like this and more in perl and would transform it to
> ruby.
> First i changed system to exec and than the points to plus , but the
> strings which are in the scalar's seems
> not be applied in the exec call , perhaps some special needs with
> quoting!?
>
> :perl
> foreach $line(@methoden) {
> system("$exe_path" . "dti.exe -qb -t -e$line $dom_file
> $train_file $modell_string" . "$line" . ".dti");
> .................
> }
>
> :ruby
>
> methoden.each do |line|
> exec("exe_path + dti.exe -qb -t -eline dom_file train_file
> modell_string + line + .dti")
> .............
> end
>
> many thanks christian

String interpolation does this nicely:

methoden.each do |line|
exec("#{exe_path}dti.exe -qb -t -e#{line} #{dom_file} #{train_file}
#{modell_string}#{line}.dti")
.............
end

Brian Candler

4/18/2007 5:32:00 AM

0

On Tue, Apr 17, 2007 at 11:55:06PM +0900, Christian wrote:
> :perl
> foreach $line(@methoden) {
> system("$exe_path" . "dti.exe -qb -t -e$line $dom_file
> $train_file $modell_string" . "$line" . ".dti");
> .................
> }

Instead of $var write #{var}

Alternatively, let Ruby deal with the individual arguments:

system(exe_path, "-qb", "-t", "-e" + line, dom_file, train_file,
modell_string + line + ".dti")

This is safer as it will work even if the arguments themselves contain
spaces.