From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [Proposal] Why not add a "shell" procedure? Date: Sun, 13 May 2012 14:29:12 -0400 Message-ID: <87y5owkk93.fsf@netris.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1336933838 30665 80.91.229.3 (13 May 2012 18:30:38 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 13 May 2012 18:30:38 +0000 (UTC) Cc: guile-devel To: Nala Ginrut Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun May 13 20:30:37 2012 Return-path: Envelope-to: guile-devel@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 1STdYz-0003Cu-3Z for guile-devel@m.gmane.org; Sun, 13 May 2012 20:30:37 +0200 Original-Received: from localhost ([::1]:39194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1STdYy-0002Xb-EO for guile-devel@m.gmane.org; Sun, 13 May 2012 14:30:36 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1STdYv-0002XW-GR for guile-devel@gnu.org; Sun, 13 May 2012 14:30:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1STdYt-0008Bh-UV for guile-devel@gnu.org; Sun, 13 May 2012 14:30:33 -0400 Original-Received: from world.peace.net ([96.39.62.75]:52336) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1STdYt-0008Ak-Pz for guile-devel@gnu.org; Sun, 13 May 2012 14:30:31 -0400 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1STdYb-0000GY-Li; Sun, 13 May 2012 14:30:14 -0400 In-Reply-To: (Nala Ginrut's message of "Sat, 12 May 2012 20:30:21 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:14406 Archived-At: Hi Nala, Nala Ginrut writes: > (define %current-shell (getenv "SHELL")) > (use-modules (ice-9 popen) (rnrs io ports)) > (define shell > (lambda (cmd) > (let ((str (string-append %current-shell " -c " cmd))) > (get-string-all (open-pipe str OPEN_READ))))) (open-pipe ...) already does '/bin/sh -c ', so (shell ) does '/bin/sh -c " -c "', i.e. it launches a shell within a shell. This is wasteful, and might also exacerbate problems when shell metacharacters are present in or . Therefore, better do (open-pipe* OPEN_READ %current-shell "-c" cmd) instead. Also, I recommend making '%current-shell' a fluid, and perhaps adding a keyword argument to 'shell' to specify the shell directly, so that '%current-shell' is only used as the default for the keyword argument. Note that although it is convenient to pass strings directly to the shell, it is fraught with security risks due to the complexity of escaping shell metacharacters properly, especially given the diversity of shells and shell configurations. Therefore, it is better not to encourage this way of doing things. It is generally better to use 'open-pipe*' or 'system*' directly, to avoid the shell entirely. Thanks, Mark