From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Amirouche Newsgroups: gmane.lisp.guile.bugs Subject: bug#15228: making open-process public Date: Sun, 5 Mar 2017 21:41:56 +0100 Message-ID: <450ba7d0-800e-3c65-4d32-e9b40747cd64@hypermove.net> References: <1377937797.2030.5.camel@qwghlm> <145cea679b38ca9de4e8b1c9f2213622@hypermove.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7374C500BE0D7988597430D2" X-Trace: blaine.gmane.org 1488746539 14874 195.159.176.226 (5 Mar 2017 20:42:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 5 Mar 2017 20:42:19 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 To: 15228@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sun Mar 05 21:42:14 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ckcyp-0002pu-41 for guile-bugs@m.gmane.org; Sun, 05 Mar 2017 21:42:11 +0100 Original-Received: from localhost ([::1]:40304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckcyt-0001Dt-Lm for guile-bugs@m.gmane.org; Sun, 05 Mar 2017 15:42:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckcyk-0001Bv-Qh for bug-guile@gnu.org; Sun, 05 Mar 2017 15:42:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckcyg-00061W-SN for bug-guile@gnu.org; Sun, 05 Mar 2017 15:42:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43166) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ckcyg-00061H-NO for bug-guile@gnu.org; Sun, 05 Mar 2017 15:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ckcyg-00073D-Bz for bug-guile@gnu.org; Sun, 05 Mar 2017 15:42:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Amirouche Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 05 Mar 2017 20:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15228 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch Original-Received: via spool by 15228-submit@debbugs.gnu.org id=B15228.148874651627091 (code B ref 15228); Sun, 05 Mar 2017 20:42:02 +0000 Original-Received: (at 15228) by debbugs.gnu.org; 5 Mar 2017 20:41:56 +0000 Original-Received: from localhost ([127.0.0.1]:41365 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ckcya-00072t-8L for submit@debbugs.gnu.org; Sun, 05 Mar 2017 15:41:56 -0500 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:38079) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ckcyY-00072j-5N for 15228@debbugs.gnu.org; Sun, 05 Mar 2017 15:41:54 -0500 Original-Received: from [IPv6:2a01:e35:2ef3:d930:1d63:a765:189:27df] (unknown [IPv6:2a01:e35:2ef3:d930:1d63:a765:189:27df]) (Authenticated sender: amirouche@hypermove.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id AB3501720AC for <15228@debbugs.gnu.org>; Sun, 5 Mar 2017 21:41:52 +0100 (CET) In-Reply-To: <145cea679b38ca9de4e8b1c9f2213622@hypermove.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8651 Archived-At: This is a multi-part message in MIME format. --------------7374C500BE0D7988597430D2 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Sorry I have an issue with my mail I can't find the mail where you asked for a patch. Attached to this mail my very first patch. Le 03/09/2016 à 09:33, Amirouche Boubekki a écrit : > Wingo wrote: > >> We could just expose `open-process' from (ice-9 popen) to start with. > > AFAIK, that's what Mark wants. > > Here is an example use of `open-process' to wrap `html2text': > > > (use-modules (ice-9 popen)) > > (define open-process (@@ (ice-9 popen) open-process)) > > (define (html2text string) > (with-error-to-file "/dev/null" > (lambda () > (call-with-values (lambda () (open-process OPEN_BOTH > "html2text")) > (lambda (read-port write-port pid) > (display string write-port) > (close-port write-port) > (let ((str (read-string read-port))) > (close-port read-port) > (waitpid pid) > str)))))) > > IIUC to achieve this goal, I need to make `open-process' public > in `ice-9 popen` module and add documentation for it? > > Is that correct? > > > --------------7374C500BE0D7988597430D2 Content-Type: text/x-patch; name="0002-make-open-process-public-in-ice-9-popen.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-make-open-process-public-in-ice-9-popen.patch" >From 997e521e2368c771822b9741e47850665f7715f1 Mon Sep 17 00:00:00 2001 From: Amirouche Date: Sun, 5 Mar 2017 21:37:09 +0100 Subject: [PATCH 2/2] make open-process public in (ice-9 popen) --- doc/ref/posix.texi | 60 ++++++++++++++++++++++++++++++++++++++++++-------- module/ice-9/popen.scm | 2 +- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index 4afe6bf..53f2230 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -2161,12 +2161,12 @@ expiry will be signalled. A real-time timer, counting down elapsed real time. At zero it raises @code{SIGALRM}. This is like @code{alarm} above, but with a higher resolution period. -@end defvar +@end defvar @defvar ITIMER_VIRTUAL A virtual-time timer, counting down while the current process is actually using CPU. At zero it raises @code{SIGVTALRM}. -@end defvar +@end defvar @defvar ITIMER_PROF A profiling timer, counting down while the process is running (like @@ -2175,7 +2175,7 @@ process's behalf. At zero it raises a @code{SIGPROF}. This timer is intended for profiling where a program is spending its time (by looking where it is when the timer goes off). -@end defvar +@end defvar @code{getitimer} returns the restart timer value and its current value, as a list containing two pairs. Each pair is a time in seconds and @@ -2260,6 +2260,48 @@ module@footnote{This module is only available on systems where the (use-modules (ice-9 popen)) @end lisp +@findex open-process +@deffn {Scheme Procedure} open-process mode command [args...] + +Execute @code{command} in a subprocess passing @code{args} as arguments. + +@code{open-process} is the procedure used by and @code{open-pipe} +and else to communicate with a subprocess using pipes. The notable +difference with @code{open-pipe} API is that @code{open-process} +does return multiple values. + +It returns @code{read-port}, @code{write-port} and @code{pid}. Depending +on the @code{mode} you open the subprocess you can access +@code{read-port} and @code{write-port} using regular port procedures. +In particular you can close the @code{read-port} without closing the +@code{write-port}. Don't forget to call @code{waitpid} on @code{pid}. + +Here is an example program that calls @code{tr} that request to replace +@code{qsdf} with @code{asdf}: + +@lisp +(use-modules (ice-9 rdelim)) +(use-modules (ice-9 popen)) + + +(define open-process (@@ (ice-9 popen) open-process)) + +(define (qsdf->asdf string) + (call-with-values (lambda () (open-process OPEN_BOTH "tr" "qsdf" "asdf")) + (lambda (read-port write-port pid) + (display string write-port) + (close-port write-port) + (let ((str (read-string read-port))) + (close-port read-port) + (waitpid pid) + str)))) + + +(pk (qsdf->asdf "qsdf is fun!")) +@result{} "asdf is fun!" +@end lisp +@end deffn + @findex popen @deffn {Scheme Procedure} open-pipe command mode @deffnx {Scheme Procedure} open-pipe* mode prog [args...] @@ -2356,11 +2398,11 @@ the garbage collector pick them up at some later time. @cindex network @menu -* Network Address Conversion:: -* Network Databases:: -* Network Socket Address:: -* Network Sockets and Communication:: -* Internet Socket Examples:: +* Network Address Conversion:: +* Network Databases:: +* Network Socket Address:: +* Network Sockets and Communication:: +* Internet Socket Examples:: @end menu @node Network Address Conversion @@ -3167,7 +3209,7 @@ effect but the value in Guile is always a pair. @c Note that we refer only to ``man ip'' here. On GNU/Linux it's @c ``man 7 ip'' but on NetBSD it's ``man 4 ip''. -@c +@c For IP level (@code{IPPROTO_IP}) the following @var{optname}s are defined (when provided by the system). See @command{man ip} for what they mean. diff --git a/module/ice-9/popen.scm b/module/ice-9/popen.scm index 26a7e0a..37ea068 100644 --- a/module/ice-9/popen.scm +++ b/module/ice-9/popen.scm @@ -22,7 +22,7 @@ :use-module (ice-9 threads) :use-module (srfi srfi-9) :export (port/pid-table open-pipe* open-pipe close-pipe open-input-pipe - open-output-pipe open-input-output-pipe)) + open-output-pipe open-input-output-pipe open-process)) (eval-when (expand load eval) (load-extension (string-append "libguile-" (effective-version)) -- 2.9.3 --------------7374C500BE0D7988597430D2 Content-Type: text/x-patch; name="0001-whitespace-cleanup.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-whitespace-cleanup.patch" >From ae9587457b502234fc137644a12bbd754e6fdc0c Mon Sep 17 00:00:00 2001 From: Amirouche Date: Sun, 5 Mar 2017 21:38:27 +0100 Subject: [PATCH 1/2] whitespace cleanup --- module/ice-9/popen.scm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/module/ice-9/popen.scm b/module/ice-9/popen.scm index b166e9d..26a7e0a 100644 --- a/module/ice-9/popen.scm +++ b/module/ice-9/popen.scm @@ -2,21 +2,21 @@ ;;;; Copyright (C) 1998, 1999, 2000, 2001, 2003, 2006, 2010, 2011, 2012, ;;;; 2013 Free Software Foundation, Inc. -;;;; +;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public ;;;; License as published by the Free Software Foundation; either ;;;; version 3 of the License, or (at your option) any later version. -;;;; +;;;; ;;;; This library is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;;; Lesser General Public License for more details. -;;;; +;;;; ;;;; You should have received a copy of the GNU Lesser General Public ;;;; License along with this library; if not, write to the Free Software ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -;;;; +;;;; (define-module (ice-9 popen) :use-module (ice-9 threads) @@ -144,4 +144,3 @@ information on how to interpret this value." (define (open-input-output-pipe command) "Equivalent to @code{open-pipe} with mode @code{OPEN_BOTH}" (open-pipe command OPEN_BOTH)) - -- 2.9.3 --------------7374C500BE0D7988597430D2--