1

I have the following tcl script:

puts "The total number of arguments is $argc"
if {$argc > 0} {puts "The arguments in ARGV are: $argv" }
exec python  $argv/../scripts/sim/sim_comp_gen.py

How can I exec the python script ans pass it the $argv?

2 Answers 2

2

The {*} syntax is key here:

exec python ../scripts/sim/sim_comp_gen.py {*}$argv

If you're making it relative to the name of the script, that's in $argv0 and Tcl has some built-in utilities for making that easier:

set script [file join [file dirname $argv0] scripts/sim/sim_comp_gen.py]
exec python $script {*}$argv

You might need file nativename on Windows. (I can't remember if python does the slash-type ignoring/conversion.)

set script [file join [file dirname $argv0] scripts/sim/sim_comp_gen.py]
exec python [file nativename $script] {*}$argv

On a very old version of Tcl that doesn't support {*}? Use eval carefully

set script [file join [file dirname $argv0] scripts/sim/sim_comp_gen.py]
eval [list exec python $script] $argv

The key is to use list to de-fang things. That works even when you've got tricky things like spaces in filenames.

Sign up to request clarification or add additional context in comments.

Comments

1

Donal's solution is the best. You can try out below as well.

exec echo "python_script_name.py argument1 argument2" > ./tempfile
exec chmod +x ./tempfile
exec ./tempfile

Let me know if it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.