Why is my script not working in tcl language

Moderators: cyao, michael_borland

Post Reply
nadolski
Posts: 24
Joined: 20 Mar 2013, 05:03
Location: Synchrotron SOLEIL, Gif-sur-Yvette, France
Contact:

Why is my script not working in tcl language

Post by nadolski » 20 Mar 2013, 18:07

Hi,

When I run the following script I got the error:
argument runNano.twi is invalid: too many filenames (sddsprocess)
while executing
"exec sddsprocess $fileName.twi -define=column,sqrtBetax,"betax sqrt" \
$fileName.twi -define=column,sqrtBetay,"betay sqrt" "
(file "./runNano_tcl.sh" line 48)

If I run the same as a shell script, I got the correct answer
sddsprocess $fileName.twi -define=column,sqrtBetax,"betax sqrt" $fileName.twi -define=column,sqrtBetay,"betay sqrt"

Could you please tell me what is the error of the tcl syntax?

Best regards,

Laurent.

--------------------------
#!/bin/sh
# \
exec tclsh "$0" "$@"

# Define a variable: command name
set fileName runNano
puts "reading $fileName.lte ..."

if ![file exists $fileName.log] {
catch {exec elegant $fileName.ele > $fileName.log}
}

exec sddsprocess $fileName.twi -define=column,sqrtBetax,"betax sqrt" \
$fileName.twi -define=column,sqrtBetay,"betay sqrt"

michael_borland
Posts: 1933
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Why is my script not working in tcl language

Post by michael_borland » 20 Mar 2013, 18:14

Laurent,

Tcl has a different way of interpreting the quotation marks, so you need to use quotation marks around the entire argument, as in

Code: Select all

sddsprocess $fileName.twi "-define=column,sqrtBetax,betax sqrt" $fileName.twi "-define=column,sqrtBetay,betay sqrt" 
This will work in the unix shell as well, so it is a good habit to just do it that way all the time.

--Michael

michael_borland
Posts: 1933
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Why is my script not working in tcl language

Post by michael_borland » 20 Mar 2013, 18:15

Also, you don' t need to give the filename twice if you intend to overwrite the file. It will happen automatically if you only give one filename.

nadolski
Posts: 24
Joined: 20 Mar 2013, 05:03
Location: Synchrotron SOLEIL, Gif-sur-Yvette, France
Contact:

Re: Why is my script not working in tcl language

Post by nadolski » 21 Mar 2013, 02:33

Hi Michael,

Thanks for the help. It works

What about this line? Where should I put the quotation marks?

exec sddsprocess -reprint=param,aLabel,"nux: %.4f nuy: %.4f ex0: %.4f", nux,nuy,ex0 $fileName.twi

reading runNano.lte ...
argument %.4f is invalid: too many filenames (sddsprocess)
while executing
"exec sddsprocess -reprint=param,aLabel,"nux: %.4f nuy: %.4f ex0: %.4f",nux,nuy,ex0 \
$fileName.twi"
(file "./runNano_tcl.sh" line 13)

michael_borland
Posts: 1933
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Why is my script not working in tcl language

Post by michael_borland » 22 Mar 2013, 09:24

Laurent,

All arguments with spaces should have the quotation marks around the entire argument, as in

Code: Select all

exec sddsprocess "-reprint=param,aLabel,nux: %.4f nuy: %.4f ex0: %.4f, nux,nuy,ex0" $fileName.twi
I should probably change the manuals to reflect this, since it works in all shells.

--Michael

nadolski
Posts: 24
Joined: 20 Mar 2013, 05:03
Location: Synchrotron SOLEIL, Gif-sur-Yvette, France
Contact:

Re: Why is my script not working in tcl language

Post by nadolski » 22 Mar 2013, 22:35

Michael,

This is what I tried but it does not work unfortunately as you can see:

couldn't print to make parameter aLabel
while executing
"exec sddsprocess "-reprint=param,aLabel,nux: %.4f nuy: %.4f ex0: %.4f, nux,nuy,ex0" $fileName.twi"
(file "./runNano_tcl.sh" line 16)

Laurent.

michael_borland
Posts: 1933
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Why is my script not working in tcl language

Post by michael_borland » 22 Mar 2013, 22:42

Laurent,

Try deleting the space before "nux". I.e., ",nux" instead of ", nux".

--Michael

nadolski
Posts: 24
Joined: 20 Mar 2013, 05:03
Location: Synchrotron SOLEIL, Gif-sur-Yvette, France
Contact:

Re: Why is my script not working in tcl language

Post by nadolski » 23 Mar 2013, 06:33

This is indeed tricky
I will get accustomed to it with time
Thx

Post Reply