chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Controlling output of processes


From: Peter Bex
Subject: Re: [Chicken-users] Controlling output of processes
Date: Fri, 12 Mar 2010 19:37:53 +0100
User-agent: Mutt/1.4.2.3i

On Fri, Mar 12, 2010 at 07:30:34PM +0100, Lasse Kliemann wrote:
> Hello Peter, thank you for the answer. I tried it out, but it 
> does not work like the thing I wanted. Here is an example:
> 
> (receive
>    (p-stdout p-stdin p-pid p-stderr)
>    (process* "ls" '("-l"))
>    (with-input-from-port p-stdout (lambda () (process-wait p-pid))))
> 
> When I run this, I receive no output. The goal was that my 
> program hands the output of "ls -l" through. So this program was 
> supposed to give exactly the output of "ls -l". You know what I 
> mean?

Hi Lasse,

I think I do.  The idea of calling with-input-from-port is that you
put the code that reads from that port inside the thunk.  Just waiting
for the process isn't enough; there has to be some code that actually
reads out the data from stdout.

Here's an example:
(receive (p-stdout p-stdin p-pid p-stderr)
    (process* "ls" '("-l")) 
  (let ((output (with-input-from-port p-stdout read-lines)))
    (process-wait p-pid)
    output))

This returns a list of strings, with one entry for each line that is
output by "ls".  If you would like something else, you can change
read-lines by  (lambda () <whatever you want to do>)

> (I replaced "p-stdin" by "p-stdout" in the call to 
> "with-input-from-port" because this looked more appropriate to 
> me, but it also does not work when I use "p-stdin" there, as your 
> example suggested.)

Yeah, it looks more appropriate, but the input/output distinction is
turned inside-out here.  The stdout port is an output port from the
point of view of the invokED app ("ls"), but it's an input port from
the point of view of the invokING app (your chicken app).
Confusing, I know.

I hope this is a bit clearer now.

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth




reply via email to

[Prev in Thread] Current Thread [Next in Thread]