[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Possible stack problem with fork
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] Possible stack problem with fork |
Date: |
Thu, 3 Feb 2005 07:56:16 -0800 |
On Wed, 02 Feb 2005 23:19:36 +0100, Peter Bex <address@hidden> wrote:
> Hi all,
>
> I've encountered a really strange bug, and I'm wondering if it's my
> own mistake or there's a bug somewhere in chicken.
>
> The code I have is this:
>
> (define (run-and-catch-output program args)
> (call-with-values
> create-pipe
> (lambda (in out)
> (let* ([child (lambda ()
> (file-close in) ; Close read
> end
> (duplicate-fileno out fileno/stdout) ; out = stdout
> (process-execute program args))]
> [child-pid (process-fork child)])
> (file-close out) ; Close write end
> (let ([str (read-string in)]) ; Read out entire file as
> string
> (process-wait child-pid) ; Clean up zombie
> str) )) )) ; Return string
- you didn't pass the length indicator to read-string (the first argument)
- read-string only works for ports, not file-descriptors, use file-read
instead.
- process-wait returns multiple values, this triggers the error, since
it is not called in a multiple values context [1]
>
>
> Note the second error message. Somehow the string "display" is getting
> mangled.
>
I'm not sure about this, perhaps due to the error the I/O gets somehow
mixed up.
I will add a second optional parameter to `process' that can be
used to specify a list of arguments and which will invoke the program
directly (not via the shell) - `process' is much easier to use than
doing everything by hand (I would check this in, but I'm currently
behind a firewall).
[1] this is R5RS compliant, but at the same time sometimes a bit
inconvenient - I'm thinking about relaxing this a little (allowing
returning multiple values in a single value context). It could be
implemented by returning only the first value (or void, if zero
values are returned).
cheers,
felix