exec $cmd not work?

Posted by ccc123 on 2009-09-27 11:14

tried the following commands:

set cmd [concat [auto_execok ping] " www.yahoo.com"]
C:/WINDOWS/system32/ping.EXE www.yahoo.com
exec $cmd
couldn't execute "C:\WINDOWS\system32\ping.EXE www.yahoo.com": no such file or directory

it gave error

changed it to:

exec C:/WINDOWS/system32/ping.EXE www.yahoo.com

Pinging www-real.wa1.b.yahoo.com [69.147.76.15] with 32 bytes of data:

it's ok.

for command exec, how to use string var like this:

exec $cmd

thanks

ccc123 | Sun, 2009-09-27 11:27

eval exec $cmd

Pinging www-real.wa1.b.yahoo.com [69.147.76.15] with 32 bytes of data:

why should add eval in front?

niobe | Sun, 2009-09-27 15:28

That's because internally eval treats each argument as a list and concatenates multiple arguments.
So you could see it as:

eval [list exec [list ping.exe www.yahoo.com] ]

which concatenated becomes:

eval [list exec ping.exe www.yahoo.com]

exec on the other hand sees a single argument "$cmd" and doesn't realise it's a list containing a command and an argument.