guile-user
[Top][All Lists]
Advanced

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

A better way to run shell cmd?


From: Nala Ginrut
Subject: A better way to run shell cmd?
Date: Wed, 13 Jun 2012 14:55:14 +0800

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?

Unlimited to "sed", I expect any shell cmd could be used in this way.
And I think it's easy to implement it with fork-then-exec. But I think
it's better do it with our (ice-9 popen).

I think the alternative way would be:
------------------code----------------
(define (sed pattern str)
  (let ((p (open-input-output-pipe (string-append "echo -n " str "|sed
" pattern))))
         (get-string-all p)))
-------------------end-----------------
which works but less elegant to the former.

Or anyone provide a better solution for shell cmd?



reply via email to

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