This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: Fork and read my child's output
- To: Andrew Ho <andrew at tellme dot com>
- Subject: Re: Fork and read my child's output
- From: Marius Vollmer <mvo at zagadka dot ping dot de>
- Date: 21 Jun 2000 18:48:21 +0200
- Cc: Guile Mailing List <guile at sourceware dot cygnus dot com>
- References: <Pine.BSF.4.21.0006210016430.20708-201000@never.tellme.com>
Andrew Ho <andrew@tellme.com> writes:
> I wrote a Guile test script with pipe and primitive-fork which
> should have the child writing one line of text for the parent to
> read. However, it aborts and core dumps.
When running your pipes.scm, I get this:
ERRORERROR: In procedure string:
ERROR: Wrong type argument (expecting CHARP): "inside child, pid = "
: In procedure string:
ERROR: Wrong type argument (expecting CHARP): "inside parent, pid = "
That is, there are some errors in your usage of `string'.
However, Guile should not crash. Can you give more details about your
version of Guile, and the system you are running it on?
> Attached are two files: pipes.scm (the Guile test script to do this) and
> pipes.pl (the Perl version of this, which works fine).
This version of pipes works fine for me, as well:
#!/usr/local/bin/guile -s
!#
;; pipes.scm - demonstrate IPC with fork and pipe in Guile Scheme
;; Andrew Ho (andrew@tellme.com)
(let* ((connect-pipe (pipe))
(reader-pipe (car connect-pipe))
(writer-pipe (cdr connect-pipe))
(child-pid (primitive-fork)))
(if (= child-pid 0)
(begin
(close-input-port reader-pipe)
(format #t "inside child pid = ~A\n" (getpid))
(format writer-pipe "child pid ~A is sending this\n" (getpid))
(close-output-port writer-pipe))
(begin
(close-output-port writer-pipe)
(format #t "inside parent, pid = ~A, child pid = ~A\n"
(getpid) child-pid)
(format #t "reading from child: ~A\n" (read-line reader-pipe))
(close-input-port reader-pipe)
(waitpid child-pid 0))))
It produces this output:
inside parent, pid = inside child pid = 865
864, child pid = 865
reading from child: child pid 865 is sending this