Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

Passing parameters to tcl scripts

Hi everyone! I made a simple tcl script to copy my .sof file to a network-disk folder, then convert the whole PFGA chain to the rbf format.

Is it possible to pass a parameter to the tcl script? I would like to give the name of the rbf file to the script, as a command line argument. The script is executed in the tcl consolle of Quartus II.

Up to now, the only way I could find is is to modify the tcl script with an editor. Anyone can help me? bye

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi davide.camerano,

    Command line arguments are stored in the list named 'argv'. You can get the first argument with "lindex $argv 0" and the second argument with "lindex $argv 1".

    For example, assume that hoge.tcl contains the following:

    puts "1st argument is [lindex $argv 0]"

    If you execute the script as "quartus_sh -t hoge.tcl xxx", you will get the following output:

    1st argument is xxx

    Also you can use the cmdline package to specify command line arguments like -<option> <value> . For more information on the package, please refer to the page 3-37 in the following document.

    http://www.altera.com/literature/hb/qts/qts_qii52003.pdf
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for the help. I tried to insert a parameter in my script, based on your example, and it worked with the quartus_sh command from the windows xp command prompt, but it did not work from the quartus II tcl consolle, by using the "source script_name.tcl" command. Why?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The list 'argv' is not set when you source a tcl script.

    Instead, you can define a procedure with 'proc', and call it after you source your script.

    For example, suppose you have the following code in hoge.tcl. The code block defines a procedure named 'argument'. It takes two arguments.

    proc argument {first second} {

    puts "first=$first"

    puts "second=$second"

    }

    To call the procedure, you need to source the script first:

    tcl> source hoge.tcl

    Then you can call it as follows. This example passes two arguments: aaa and bbb.

    tcl> argument aaa bbb

    The following will be output:

    first=aaa

    second=bbb

    Hope this helps.