File: pipes.esh

package info (click to toggle)
esh 0.8-7
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 508 kB
  • ctags: 542
  • sloc: ansic: 3,608; lisp: 166; makefile: 72
file content (39 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (2)
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))