[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Catching both the exit status and the output



hanche@ams.sunysb.edu (Harald Hanche-Olsen) writes
> fn %Backquote sep cmd {
>   let (tmp = /tmp/es.Bq.$pid) {
>     let (status = <={$cmd >$tmp}) {
>       result ($status ``$sep{cat $tmp; /bin/rm -f $tmp})}}}
> 
> which acts like %backquote except it prepends the exit status to the
> front of the return value.  Maybe this functionality should be in the
> primitive, and then the common ` and `` forms could chop the first
> element off the list?  My solution certainly forks and execs a lot...

Hmmm, I can see the problem.  Personally I can't see another way of resolving
this problem.  As a side issue, why not let es have an output version of a
herestring so that you can output to that rather than a file?  I think this
idea was mentioned before by someone on the list.  At first I thought that
it wasn't necessary because you could always do
	var = `cmd
but as in your example it is often necessary to capture both the exit status
and the output, and it would be nice being able to do it without tmp files.

Being able to do
	while <={line >>> var} { echo $var }
would be brilliant.

Hey whilst we're at it, why not even >>>[n] ?

Pete.