Narek
Narek

Reputation: 39881

How to get the results (standard output) of a TCL exec command?

Say I have a TCL script like this:

exec ls -l 

Now this will print out the content of current directory. I need to take that output as a string and parse it. How I can do this?

Upvotes: 18

Views: 36078

Answers (1)

Andrew Cheong
Andrew Cheong

Reputation: 30273

exec returns the output so simply set a variable to it:

set result [exec ls -l]

You may want to wrap this in a catch however:

if {[catch {exec ls -l} result] == 0} { 
    # ...
} else { 
    # ... (error)
} 

Upvotes: 21

Related Questions