capture
Returns a command's output as a string
MiniContents:
Arguments
Description
Examples
Format:
capture [ -out | -err | -both ] [ -f filename ] command
Arguments:
-out
Tells the CLI that it should only capture output that is sent to stdout. This option is the default.
-err
Tells the CLI to send the output it captures to stderr.
-both
Tells the CLI to send the output it captures to stdout and stderr.
-f filename
Tells the CLI to send the output it captures to filename.
command
The CLI command (or commands) whose output is being captured. If you are specifying more than one command, you must enclose them within braces ({ }).
Description:
The capture command executes command, capturing all output that would normally go to the console into a string. After command completes, it returns the string. This command is analogous to the UNIX shell's back-tick feature; that is, `command`. The capture command lets you obtain the printed output of any CLI command so that you can assign it to a variable or otherwise manipulate it.
Examples:
set save_stat [ capture st ]
Saves the current process status into a Tcl variable.
set vbl [ capture {foreach i {1 2 3 4} {p int2_array($i )}} ]
Saves the printed output of four array elements into a Tcl variable. Here is some sample output:
int2_array(1) = -8 (0xfff8)
int2_array(2) = -6 (0xfffa)
int2_array(3) = -4 (0xfffc)
int2_array(4) = -2 (0xfffe)
Because capture records all of the information sent to it by the commands in the foreach, you do not have to use a dlist command.
exec cat << [ capture help commands ] > cli_help.txt
Writes the help text for all TotalView commands to the cli_help.txt file.
set ofile [open cli_help.txt w]
capture -f $ofile help commands
close $ofile
Also writes the help text for all TotalView commands to the cli_help.txt file. This set of commands is more efficient than the previous command because the captured data is not buffered.