Version 0 of system : Execute pipelines directly in the POSIX shell

Updated 2009-12-28 14:03:19 by pmarin

Sometimes I find shell pipelines more easy than Tcl pipelines when you need to do glob subtitution.

proc system {str} {
        exec sh -c $str        
}

The POSIX flag -c makes sh to read commans from a string. In my case sh is linked to dash, a light and fast POSIX shell. All the string is executed by sh not by Tcl.

All the pipeline is executed by the POSIX shell so you have to use the POSIX shell redirections.

You can do things like:

>system { ls *.tcl | wc -l } 

It is a lot more clean than:

> exec ls {*}[glob *.tcl] | wc -l
>set a "hello"; set b "world"
>system [subst -novariables {a=[set a];b=[set b]; echo $a $b}]; 
hello world

Comments:

Probably It is more easy to capture errors using directly exec.