6

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

user1134991
  • 3,003
  • 2
  • 25
  • 35

1 Answers1

9

Use exec command to get the same.

set output [ exec ls ]
puts $output

Man page : exec

Dinesh
  • 16,014
  • 23
  • 80
  • 122
  • 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. – Peter Lewerin Jan 07 '15 at 06:40