From: Nala Ginrut <nalaginrut@gmail.com>
To: guile-devel <guile-devel@gnu.org>, Guile User <guile-user@gnu.org>
Subject: A better way to run shell cmd?
Date: Wed, 13 Jun 2012 14:55:14 +0800 [thread overview]
Message-ID: <CAPjoZodFMKrUc5UmRtkXkFCCzL-NgFHjx07zS92z94kRCppNmA@mail.gmail.com> (raw)
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?
next reply other threads:[~2012-06-13 6:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-13 6:55 Nala Ginrut [this message]
2012-06-13 7:19 ` A better way to run shell cmd? Daniel Hartwig
2012-06-13 10:02 ` Nala Ginrut
2012-06-14 1:57 ` gregory benison
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPjoZodFMKrUc5UmRtkXkFCCzL-NgFHjx07zS92z94kRCppNmA@mail.gmail.com \
--to=nalaginrut@gmail.com \
--cc=guile-devel@gnu.org \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).