This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Fork and read my child's output


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]