# /tmp/prun
def prun '
cmd = \'$*\'
idx = index(cmd, "|")
idx2= index(cmd, ">")
if (idx2 && (!idx || idx2 < idx)) idx=idx2
if (!idx) {
unix(cmd)
exit
}
rnum = rand()
pfile="/tmp/pipe-" SPEC "." rnum
rdef speccmd substr(cmd, 1, idx-1)
unix(sprintf("/bin/rm -f %s", pfile)) ; on(pfile) ; offt
cdef("cleanup_once", \
"close(pfile); unix(sprintf(\"/bin/rm -f %s\", pfile)); ont; \
unglobal pfile rnum;\n", "wdx")
speccmd
close(pfile) ; ont
unix(sprintf("cat %s %s", pfile, substr(cmd,idx)))
#unix(sprintf("/bin/rm -f %s", pfile) # done by cleanup_once
unglobal pfile rnum
'
|