1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# Here's a simple demonstration of interprocess communication.
# It is a double-ended pipe, with 'sort' in between as a filter.
#
# Note that the pipe is asynchronous! Unless you have some sort
# of protocol to guide you, you don't know for sure if the subprocess
# is done writing or merely taking a long time to finish.
#
# That's why we need to wait a bit before reading back from the pipe --
# 'sort' needs a bit of time to finish it's job.
#
# Also, this script would have been much easier and safer had we used
# "gobble" instead of "run".
(push "
Foo
Bar
baz
Zoop
Goop
whee
you
we
arg
Grunt
abc")
(push (file-open s ''))
# Alternatively, simply use this instead of "run":
# (push (gobble (file-open s (rot)) ~(sort)))
(run (true) (file-open s (rot)) (rot) ~(sort))
(wait 1)
(push (file-read (pop)))
(print 'Sorted output:' (nl) (top) (nl))
|