Kornshell


Table of Contents

Co-processes in Kornshell 
ksh tab completion and history 
ksh tab completion and history 

Co-processes in Kornshell 

Newsgroups: comp.unix.shell
> But it doesn't seem to be working. It starts printing to the stdout (numeric
> file descriptor: 1) only when TestProcess seems to have finished
> execution. Can anyone tell me the mechanism of running co-processes via
> shell scripts, because I've spent considerable time experimenting with it,
> and it hasn't worked out.

well, I test you script using the following TestProcess function and your script seems to be working great. I guess your problem is in your TestProcess program/function ?

function TestProcess {
        integer last=0
        while :; do
                (( last && read ))
                if (( RANDOM % 25 % 2 )); then
                        last=1
                        echo Search Pattern ok
                else
                        echo failed
                fi
        done
}
TestProcess |&
exec 3<&p
exec 4>&p
while read -u3 line
do
        print "LINE:" "$line"
        result=`echo $line| grep "Search Pattern"`
        if [ "$result" != "" ]
        then
                print "Search Pattern found..."
                print -u4 " \n"
        fi
done
# ./test
LINE: Search Pattern ok
Search Pattern found...
LINE: ko
LINE: Search Pattern ok
Search Pattern found...
LINE: Search Pattern ok
Search Pattern found...
LINE: ko
LINE: ko
LINE: ko
LINE: ko
LINE: Search Pattern ok
Search Pattern found...
LINE: Search Pattern ok
Search Pattern found...
LINE: ko
...

Cyrille.