File: unix.elpi

package info (click to toggle)
elpi 2.0.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 50,296 kB
  • sloc: ml: 18,791; makefile: 229; python: 95; sh: 7
file content (35 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (3)
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
pred works0.
works0 :-
  std.assert-ok! (unix.process.open _ ["printf", "foo\n"] _ P) "works0",
  P = (unix.process _In Out _Err),
  input_line Out Str,
  std.assert! (Str = "foo") "bad output",
  unix.process.close P ok.

pred works1.
works1 :-
  std.assert-ok! (unix.process.open _ ["cat"] _ P) "works1",
  P = (unix.process In Out _Err),
  output In "foo\n",
  close_out In,
  input_line Out Str,
  std.assert! (Str = "foo") "bad output",
  unix.process.close P ok.

pred starts-but-fails.
starts-but-fails :-
  std.assert-ok! (unix.process.open _ ["ls", "non-existent"] _ P) "starts-but-fails",
  P = (unix.process _In _Out Err),
  input_line Err L,
  print "error from: ls non-existent:" L,
  unix.process.close P (error Msg),
  print "exit code:" Msg.

pred does-not-start.
does-not-start :-
  unix.process.open "non-existent" _ _ (unix.process In Out Err) D,
  std.assert! (D = error Msg) "does-not-exists",
  print "Unix API error:" Msg,
  var In, var Out, var Err.

main :- std.spy-do! [ works0, works1, starts-but-fails, does-not-start ].