From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: A better way to run shell cmd? Date: Wed, 13 Jun 2012 14:55:14 +0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1339570528 22388 80.91.229.3 (13 Jun 2012 06:55:28 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 13 Jun 2012 06:55:28 +0000 (UTC) To: guile-devel , Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jun 13 08:55:27 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SehUC-0004e3-MH for guile-user@m.gmane.org; Wed, 13 Jun 2012 08:55:24 +0200 Original-Received: from localhost ([::1]:54069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SehUC-00076h-D8 for guile-user@m.gmane.org; Wed, 13 Jun 2012 02:55:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SehU7-00076b-HT for guile-user@gnu.org; Wed, 13 Jun 2012 02:55:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SehU5-0006Qm-VV for guile-user@gnu.org; Wed, 13 Jun 2012 02:55:19 -0400 Original-Received: from mail-vb0-f41.google.com ([209.85.212.41]:38370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SehU5-0006QM-OF; Wed, 13 Jun 2012 02:55:17 -0400 Original-Received: by vbkv13 with SMTP id v13so261344vbk.0 for ; Tue, 12 Jun 2012 23:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=6/VPaGr2hl5YOASWg0/6QBBX1fez/3Q96S0TxOw99rY=; b=S7uDrpsgkgJ4YhoJqKjd+pT1fTnOklIOrPk6hvFgjjtPSCVJKCii423NJ6mcaR28eU Zo+3YT2R1yv6HRkipzVM6nONxalw/ZZ/L/XZquqsLo6a7b08/ZwQgGSjxlGUsvb1yok2 HzfuCxBGotSIX+fwSfr2el1AHa3v35ITgocBLUFTchSmBDzIy3exas8lU/0aNSugqTFn j1Oag+YmlTj4TpbL2iGS4UHQsk7tOlcklOt7JCxWLe36KeVMQS9JVvswUBkfPIf6wUbs D+E0jEI+8sw1Kfq7ECINy9sIfvHAya9KTExHh67Kbr7VaIXMDKL2F+/v9RXQjx3BdjMh jfEQ== Original-Received: by 10.52.64.146 with SMTP id o18mr13538381vds.55.1339570514155; Tue, 12 Jun 2012 23:55:14 -0700 (PDT) Original-Received: by 10.52.34.115 with HTTP; Tue, 12 Jun 2012 23:55:14 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.41 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9499 gmane.lisp.guile.devel:14614 Archived-At: 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?