Does Tcl have an equivalent of PERL and Ruby backtic
Asked Answered
E

1

7

In Ruby/PERL, I can very easily get the console output of a system command fed into a file. For example:

$k = `ls`

Would input the output of ls into variable $k in PERL (and Ruby).
How can one do something like this in Tcl?
Thanks

Escobedo answered 6/1, 2015 at 15:51 Comment(0)
W
9

Use exec command to get the same.

set output [ exec ls ]
puts $output

Man page : exec

Woolcott answered 6/1, 2015 at 16:3 Comment(1)
May I add for completeness that while this is indeed the general solution for capturing the output from a system command, in the specific case of getting a list of file names, the glob command is more useful and portable.Nigrify

© 2022 - 2024 — McMap. All rights reserved.