-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpipes.ex
40 lines (32 loc) · 863 Bytes
/
pipes.ex
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
--****
-- === pipes.ex
--
-- Starts a sub-process and communicates to it via piped io.
-- The sub process is ##pipe_sub.ex##
--
include std/pipeio.e as pipe
include std/console.e
without warning
--@nodoc@
override procedure abort(integer x)
maybe_any_key()
eu:abort(x)
end procedure
object z = pipe:create()
object p = pipe:exec("eui pipe_sub.ex", z)
if atom(p) then
printf(1, "Failed to exec() with error %x\n", pipe:error_no())
abort(1)
end if
integer bytes = pipe:write(p[STDIN],"This data was written to pipe STDIN!\n")
printf(1,"number bytes written to child: %d\n", { bytes })
object c = pipe:read(p[STDOUT], 256)
if atom(c) then
printf(1, "Failed on read with error %x\n", pipe:error_no())
abort(1)
end if
puts(1,"read from child pipe: \""&c&"\"")
--Close pipes and make sure process is terminated
pipe:kill(p)
puts(1,"\n\n")
maybe_any_key()