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 (see below).
In the following two cases, it matters whether the CLI directly prints output or returns and then prints it:
![*](p4-bullet.jpg)
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.
![*](p4-bullet.jpg)
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 the help command only prints its output without returning a string, the following does not work:
set htext [help]
This statement assigns just an empty string to htext.
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]
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 UI, TotalView also writes this information to the Input/Output view.