Forum: Ruby exec with string in variables?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F843639d20fdac04a5cc72d4716638a5?d=identicon&s=25 Christian Schulz (ozric)
on 2007-04-17 16:55
(Received via mailing list)

i have something like this and more in perl and would transform it to
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

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


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

many thanks christian
5d042621c7c90a43d2776db19eca2023?d=identicon&s=25 Ken Mitchell (kennyd)
on 2007-04-17 17:08
(Received via mailing list)

exec("#{exe_path dti.exe -qb -t -eline #{dom_file} #{train_file}
#{modell_string} #{line} .dti")

Ruby needs #{variable} in quotes to parse variable.  Or you could
concatenate outside the quotes like:

exec(exe_path + "dti.exe -qb......" + dom_file)

Basically, it is variable + "string" + another_variable
On Tue, 2007-04-17 at 23:55 +0900, Christian wrote:

> :perl
> modell_string + line + .dti")
> .............
> end
> many thanks christian



Ken Mitchell
Wireless Operations Engineer
Farmers Wireless

CONFIDENTIALITY NOTICE: This e-mail and any attachment to it may contain
confidential and legally privileged information. This information is
intended only for the recipient named above. If you are not the intended
recipient, take notice that any disclosure, copying, distribution or
taking of any action based upon this information is prohibited by law.
If you have received this e-mail in error, please return it to the
sender and delete this copy from your system. Thank you.
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 ChrisH (Guest)
on 2007-04-17 17:21
(Received via mailing list)
On Apr 17, 10:53 am, Christian <> wrote:
>     foreach $line(@methoden) {
> .............
> 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}
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-04-18 07:33
(Received via mailing list)
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
This topic is locked and can not be replied to.