Lasse Kliemann | 22 Apr 2009 23:13

pipe chain

How can I connect serveral sub-processes by pipes, like in shell 
I do with 'cmd1 | cmd2 | cmd3' ?

Best I came up with is:

  (call-with-input-process
    '("cmd1")
    (lambda (pipe-left-end)
      (call-with-output-process
        '("cmd2")
        (lambda (pipe-right-end)
          (copy-port pipe-left-end pipe-right-end))))))

This seems to work. However, I do not see a way to redirect 
stdout of 'cmd2' to stdin of a 'cmd3'.

I have the feeling, I'm missing something fundamental here.

Thanks for a hint!
Lasse
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
(Continue reading)

Shiro Kawai | 23 Apr 2009 03:20
Favicon

Re: pipe chain

From: Lasse Kliemann <lasse-list-gauche-2009 <at> mail.plastictree.net>
Subject: [Gauche-devel] pipe chain
Date: Wed, 22 Apr 2009 23:13:17 +0200

> How can I connect serveral sub-processes by pipes, like in shell 
> I do with 'cmd1 | cmd2 | cmd3' ?

This feature has been sitting on the TODO list for long long time.
Implementing it won't be very difficult, but coming up a right
API isn't trivial if we want flexibility more than a simple pipeline.
Scsh has very thorough support on process control but I'm a bit
uncomfortable with its syntax.

So, at this moment, the easiest way is to delegate the task to
the shell:

  (run-process "cmd1 | cmd2 | cmd3" ...)

A major drawback is that, when commands and their arguments are
given from outside, you have to be very careful quoting them
correctly.

If you want just a simple straight pipe, you can write something
like this:

===============================================
(use gauche.process)
(use gauche.sequence)
(use util.list)

(Continue reading)

Alex Shinn | 23 Apr 2009 04:06
Picon

Re: pipe chain

Shiro Kawai <shiro <at> lava.net> writes:

> From: Lasse Kliemann <lasse-list-gauche-2009 <at> mail.plastictree.net>
> Subject: [Gauche-devel] pipe chain
> Date: Wed, 22 Apr 2009 23:13:17 +0200
>
>> How can I connect serveral sub-processes by pipes, like in shell 
>> I do with 'cmd1 | cmd2 | cmd3' ?
>
> This feature has been sitting on the TODO list for long long time.
> Implementing it won't be very difficult, but coming up a right
> API isn't trivial if we want flexibility more than a simple pipeline.
> Scsh has very thorough support on process control but I'm a bit
> uncomfortable with its syntax.

I've actually been working on a SRFI for this, I'd encourage
anyone interested to join the discussion when it's open.

--

-- 
Alex

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p

Gmane