Command Reference2. FPGA Express Shell Commands redirect _N_A_M_E redirect Redirects the output of a command to a file. SYNTAX string redirect [-append] _f_i_l_e__n_a_m_e {_c_o_m_m_a_n_d} string _f_i_l_e__n_a_m_e string _c_o_m_m_a_n_d ARGUMENTS -append Appends the output to _f_i_l_e__n_a_m_e. _f_i_l_e__n_a_m_e Indicates the file to which to redirect output. _c_o_m_m_a_n_d The command to execute. Intermediate output from this command, as well as the result of the command, will be redirected to _f_i_l_e__n_a_m_e. DESCRIPTION The redirect command performs the same function as the traditional unix-style redirection operators > and >>. The _c_o_m_m_a_n_d must be rigidly quoted (that is, enclosed in curly braces) in order for the operation to succeed. It must not be constructed as a nested command. The result of a redirect command which does not generate a Tcl error is the empty string. Screen output occurs only if errors occurred during execution of the _c_o_m_m_a_n_d (other than opening the redirect file). When errors occur, a summary message is outpt. See the examples. Although the result of a successful redirect command is the empty string, it is still possible to get and use the result of the command that you redirected. Construct a set command in which you set a variable to the result of your command. Then, redirect the set command. The variable holds the result of your command. See the examples. The redirect command is much more flexible that traditional unix redirection operators. With redirect, you can redirect multiple commands or an entire script. v3.0 Synopsys Inc. 1988-1998. All rights reserved. 2-1 redirect 2. FPGA Express Shell Commands Command Reference See the examples for an example of how to construct such a command. Note that the builtin Tcl command puts does not respond to output redirection of any kind. Use the builtin echo command instead. 2-2 Synopsys Inc. 1988-1998. All rights reserved. v3.0 Command Reference2. FPGA Express Shell Commands redirect EXAMPLES In the following example, the output of the plus procedure is redirected. The echoed string and the result of the plus operation is in the output file. Notice that the result was not echoed to the screen. prompt> proc plus {a b} {echo "In plus" ; return [expr $a + $b]} prompt> redirect p.out {plus 12 13} prompt> exec cat p.out In plus 25 In this example, a typo in the command created an error condition. The error message indicates that you can use error_info to trace the error, but you should first check the output file. prompt> redirect p.out {plus2 12 13} Error: Errors detected during redirect Use error_info for more info. (CMD-013) prompt> exec cat p.out Error: unknown command 'plus2' (CMD-005) In this example, we explore the usage of results from redirected commands. Since the result of redirect for a command which does not generate a Tcl error is the empty string, use the set command to trap the result of the command. For example, assume that there is a command to read a file which has a result of "1" if it succeeds, and "0" if it fails. If you redirect only the command, there is no way to know if it succeeded. redirect p.out { read_a_file "a.txt" } # Now what? How can I redirect and use the result? But if you set a variable to the result, then it is possible to use that result in a conditional expression, etc. redirect p.out { set rres [read_a_file "a.txt"] } if { $rres == 1 } { echo "Read ok!" } The redirect command is not limited to redirection of a single command. You can redirect entire blocks of a script with a single redirect command. This simple example with echo demonstrates this feature: v3.0 Synopsys Inc. 1988-1998. All rights reserved. 2-3 redirect 2. FPGA Express Shell Commands Command Reference prompt> redirect p.out { ? echo -n "Hello " ? echo "world" ? } prompt> exec cat p.out Hello world prompt> SEE ALSO echo(2), _e_r_r_o_r__i_n_f_o(2), _s_e_t(2). 2-4 Synopsys Inc. 1988-1998. All rights reserved. v3.0