guile-user
[Top][All Lists]
Advanced

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

Re: A better way to run shell cmd?


From: Nala Ginrut
Subject: Re: A better way to run shell cmd?
Date: Wed, 13 Jun 2012 18:02:19 +0800

hi Daniel, thanks for reply!
I tried guile-lib just now, it's nice. I'll use it.

Besides, do you think pipe is the proper way to implement "sed" function?
Or it's better to implement a module with pure Guile?

On Wed, Jun 13, 2012 at 3:19 PM, Daniel Hartwig <address@hidden> wrote:
> On 13 June 2012 14:55, Nala Ginrut <address@hidden> wrote:
>> hi folks! I'm on my trip and inconvenient to meet you guys on IRC.
>> Things gonna be normal next month.
>>
>> Anyway, there's a problem for you.
>> I'm trying to write a simple wrapper for "sed" with our popen module:
>> --------------code------------
>> (use-modules (ice-9 popen) (rnrs))
>> (define (sed pattern str)
>>  (let ((p (open-input-output-pipe (string-append "sed " pattern))))
>>    (display str p)
>>    (get-string-all p)))
>> ----------------end-------------
>>
>> I expect it run like this:
>> -----------------------
>> (sed "s:a:b:g" "abcabc")
>> ==> "bbcbbc"
>> -----------------------
>>
>> But it halts that I have to interrupt.
>> Is it accepted?
>>
>
> The sed program may be expecting a newline, or waiting for EOF or a
> full buffer before producing it's output.  Some users have had trouble
> with this in the past, because you can not send EOF to one end of the
> pipe without closing the other.
>
> One way around this to use run-with-pipe from the guile-lib module (os
> process).  This returns two separate pipe objects for input and
> output, thus you can close/EOF one and continue to use the other.
> Many filter programs do not flush their output until their input EOFs,
> which is why your solution using 'echo -n' works.
>
> See this thread for a short discussion:
>
> http://lists.gnu.org/archive/html/guile-user/2012-02/msg00066.html
>
> Updating guile to support closing one end of the pipe is long off on my TODO.
>



reply via email to

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