About CLI Output
A CLI command can either print its output to a window or return the output as a character string. If the CLI executes a command that returns a string value, it also prints the returned string. Most of the time, you won’t care about the difference between printing and returning-and-printing. Either way, the CLI displays information in your window. And, in both cases, printed output is fed through a simple more processor. (This is discussed in more detail in the next section.)
In the following two cases, it matters whether the CLI directly prints output or returns and then prints it:
When the Tcl interpreter executes a list of commands, the CLI only prints the information returned from the last command. It doesn’t show information returned by other commands.
You can only assign the output of a command to a variable if the CLI returns a command’s output. You can’t assign output that the interpreter prints directly to a variable, or otherwise manipulate it, unless you save it using the
capture command.
For example, the dload command returns the ID of the process object that was just created. The ID is normally printed—unless, of course, the dload command appears in the middle of a list of commands; for example:
{dload test_program;dstatus}
In this example, the CLI doesn’t display the ID of the loaded program, since the dload command was not the last command.
When information is returned, you can assign it to a variable. For example, the next command assigns the ID of a newly created process to a variable:
set pid [dload test_program]
Because you can’t assign the output of the help command to a variable, the following doesn’t work:
set htext [help]
This statement assigns an empty string to htext because the help command doesn’t return text. It just prints it.
To save the output of a command that prints its output, use the
capture command. For example, the following example writes the
help command’s output into a variable:
set htext [capture help]
NOTE: You can capture the output only from commands. You can’t capture the informational messages displayed by the CLI that describe process state. If you are using the GUI, TotalView also writes this information to the Log Window. You can display this information by using the Tools > Event Log command.