Execute a system command: Difference between revisions

No edit summary
Line 98:
 
This page uses "ls" as the primary example. For what it's worth, Tcl has built-in primitives for retrieving lists of files so one would rarely ever directly exec an ls command.
 
It is also possible to execute a system command by "open"ing it through a pipe from whence any output of the command can be read at any (later) time. For example:
 
set io [open "|ls" r]
 
would execute "ls" and pipe the result into the unit "io". From there one could receive it either line by line like this:
 
set nextline [gets $io]
or read the whole shebang in a fell swoop:
 
set lsoutput [read $io]
 
==[[UNIX Shell]]==
Anonymous user