Thursday, May 16, 2013

Introduction to bash coprocess

A complicated way to do something very simple. I suppose I need to brush up more on my bash file descriptor chops.
$ coproc virsh
[1] 14358
$ cat > flywheel.xml <&${COPROC[0]}
^Z
[2]+  Stopped                 cat > flywheel.xml 0<&${COPROC[0]}
$ bg
$ echo 'dumpxml flywheel' >&${COPROC[1]}
$ echo 'exit' >&${COPROC[1]}
$ 
[1]-  Done                    coproc COPROC virsh
[2]+  Done                    cat > flywheel.xml 0<&${COPROC[0]}
It may not be as efficient as this for small jobs:
echo "dumpxml $d" | virsh > $dest
But for driving longer running processes, this might be kinda cool.

No comments:

Post a Comment