Calling External Programs - 2020.2 English

Vivado Design Suite User Guide: Using Tcl Scripting (UG894)

Document ID
Release Date
2020.2 English

It is possible to call external programs from within Tcl and capture the returned result. Although there is an automated mechanism to send unknown Tcl commands to the OS (Windows/Linux) for execution, it is always recommended to be explicit when calling external programs or commands. This is done using the exec command.

It is important to use the exec command for consistency of results, to make sure that the script works under every host OS (Windows or Linux) and all Vivado modes (Tcl mode, GUI, or batch mode).

The following example (Linux) gets the list of all files and directories under the run directory by calling the ls command.

vivado% set result [exec ls]
vivado% foreach element [split $result \n] { ... }

The equivalent example on Windows is shown below.

vivado% set result [exec cmd /c dir /B]
vivado% foreach element [split $result \n] { ... }

It is not recommended to call the ls command without exec as the script could fail in some of the Vivado modes (see Vivado Integrated Design Environment (IDE)/Tcl Modes versus Batch Mode).

The next example executes a Perl script and sends the result to the Tcl environment. Note that the exec command calls /bin/perl (assuming it matches your environment), which in turn calls the Perl script itself:

vivado% set result [exec /bin/perl <path_to>/]