File: shproc.scm

package info (click to toggle)
pact 980714-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 13,096 kB
  • ctags: 26,034
  • sloc: ansic: 109,076; lisp: 9,645; csh: 7,147; fortran: 1,050; makefile: 136; lex: 95; sh: 32
file content (57 lines) | stat: -rw-r--r-- 1,432 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;
; SHPROC.SCM - test the process control capabilities both of PPC and SCHEME
;

(define (send-command proc cmd)
    (printf nil "\nSending: %s\n" cmd)
    (process-send-line proc cmd)
    (display-response proc)
    (show-status proc))

(define (show-status proc)
    (let* ((stat (process-status proc))
	   (runs (cdddr stat))
	   (runp (car runs))
	   (reason (cadr runs)))
          (printf nil
		  "Status for process \#%d: %s\n"
		  (car stat)
		  (cond ((= runp 0)  "Running")
			((= runp 1)  (sprintf "Stopped (%d)" reason))
			((= runp 2)  (sprintf "Changed (%d)" reason))
			((or (= runp 4) (= runp 6))
			 (sprintf "Exited (%d)" reason))
			((or (= runp 8) (= runp 10))
			 (sprintf "Coredumped (%d)" reason))
			((= runp 16) (sprintf "Signaled (%d)" reason))
			(else        (sprintf "Unkown (%d %d)" runp reason))))))

(define (display-response proc)
    (let* ((s (process-read-line proc)))
          (if s
	      (begin (printf nil "| %s" s)
		     (display-response proc))
	      (printf nil "\n"))))

(printf nil "Old # read attempts: %d\n" (process-read-tries))
(printf nil "New # read attempts: %d\n" (process-read-tries 10000))

(printf nil "\n")

(define child (process-open "a" "scheme"))

(show-status child)
(display-response child)

(send-command child "(car (list 1 2 3))")

(send-command child "(describe process-status)")

(send-command child "(quit)")

(process-close child)

(printf nil "\n")

(quit)