Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  pipe output of a command back into a Tcl parsing procedure?
 For example, to grep a pattern out of a range of files, one might
do: (Karl Lehenbauer) writes:

set files [glob /home/cole/stats/*]

proc parseInfo { site } {
   global files

# site is chosen from a listbox earlier
   set in [open [concat "|/usr/bin/grep $site $files"] r]

   while {[gets $in line]>-1} {
      puts stderr $line
   catch {close $in}

One thing:  the matching strings are _not_ returned in directory order.

But what if I want to check the return code AND use the output of 
the command? (Kevin B. Kenny) writes:

if [catch {exec ls} data] {
        # The exec got an error, and $errorCode has its termination status
} else {
        # The exec succeeded
# In any case, `data` contains all the output from the child process.

Note that Karl Lehenbauer adds that errorCode will be a list containing
three elements, the string "CHILDSTATUS", the process ID of the child,
and the exit status of the child.