Welcome to the CHICKEN Scheme pasting service

Why does the parent die when I close the ports? added by alaricsp on Tue Jun 25 13:30:00 2013

(use posix)

(define (process** cmd #!optional args env)
  (let*-values
      (((in-in   in-out) (create-pipe))
       ((out-in out-out) (create-pipe))
       ((err-in err-out) (create-pipe))
       ((pid) (process-fork
               (lambda ()
                 (duplicate-fileno in-in fileno/stdin)
                 (duplicate-fileno out-out fileno/stdout)
                 (duplicate-fileno err-out fileno/stderr)
                 (file-close in-out)
                 (file-close in-in)
                 (file-close out-in)
                 (file-close out-out)
                 (file-close err-in)
                 (file-close err-out)
                 (process-execute cmd args env)))))
    (file-close in-in)
    (file-close out-out)
    (file-close err-out)
    (values (open-input-file*  out-in)
            (open-output-file* in-out)
            pid
            (open-input-file*  err-in))))

(printf "Thingying:\n")
(let-values (((responses commands pid errors)
              (process** "/bin/cat")))
  (printf "Ok, let's go\n")
  (write '(1 2 3) commands)
  (set! foo (read responses))
  (printf "Got ~A\n" foo)
  (close-input-port responses)
  (close-output-port commands)
  (printf "Ports closed\n")
  (process-wait pid)
  (printf "Child process gone\n"))

(printf "Result: ~A\n" foo)

alaric@gunka:~/personal/projects/ugarit$ csi -script test.scm
Thingying:
Ok, let's go
Got #!eof

s/process**/process*/:

(printf "Thingying:\n")
(let-values (((responses commands pid errors)
              (process* "/bin/cat")))
  (printf "Ok, let's go\n")
  (write '(1 2 3) commands)
  (set! foo (read responses))
  (printf "Got ~A\n" foo)
  (close-input-port responses)
  (close-output-port commands)
  (printf "Ports closed\n")
  (process-wait pid)
  (printf "Child process gone\n"))

(printf "Result: ~A\n" foo)

alaric@gunka:~/personal/projects/ugarit$ csi -script test.scm
Thingying:
Ok, let's go
Got (1 2 3)
Ports closed
Child process gone
Result: (1 2 3)

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What type of object does `for-each' expect as second argument?
Visually impaired? Let me spell it for you (wav file) download WAV