GNU logs - #15228, boring messages


Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15228: [PATCH] Close output port of I/O pipes
Resent-From: Josep Portella Florit <jpf@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Sat, 31 Aug 2013 08:31:01 +0000
Resent-Message-ID: <handler.15228.B.13779378561056 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 15228
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: patch
To: 15228 <at> debbugs.gnu.org
X-Debbugs-Original-To: bug-guile@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.13779378561056
          (code B ref -1); Sat, 31 Aug 2013 08:31:01 +0000
Received: (at submit) by debbugs.gnu.org; 31 Aug 2013 08:30:56 +0000
Received: from localhost ([127.0.0.1]:60996 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1VFga7-0000FY-1c
	for submit <at> debbugs.gnu.org; Sat, 31 Aug 2013 04:30:55 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49043)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <jpf@HIDDEN>) id 1VFga3-00006O-Hm
 for submit <at> debbugs.gnu.org; Sat, 31 Aug 2013 04:30:52 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <jpf@HIDDEN>) id 1VFgZo-0001A9-R5
 for submit <at> debbugs.gnu.org; Sat, 31 Aug 2013 04:30:46 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:49050)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <jpf@HIDDEN>) id 1VFgZo-0001A4-NY
 for submit <at> debbugs.gnu.org; Sat, 31 Aug 2013 04:30:36 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:50746)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <jpf@HIDDEN>) id 1VFgZg-0002bx-WA
 for bug-guile@HIDDEN; Sat, 31 Aug 2013 04:30:36 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <jpf@HIDDEN>) id 1VFgZL-00013z-QH
 for bug-guile@HIDDEN; Sat, 31 Aug 2013 04:30:28 -0400
Received: from primfilat.com ([71.19.154.166]:43381)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <jpf@HIDDEN>) id 1VFgZL-00010T-Ez
 for bug-guile@HIDDEN; Sat, 31 Aug 2013 04:30:07 -0400
Received: from [192.168.0.102] (unknown [46.18.40.145])
 by primfilat.com (Postfix) with ESMTPSA id 5B0E67B8A0
 for <bug-guile@HIDDEN>; Sat, 31 Aug 2013 10:44:02 +0200 (CEST)
Message-ID: <1377937797.2030.5.camel@qwghlm>
From: Josep Portella Florit <jpf@HIDDEN>
Date: Sat, 31 Aug 2013 10:29:57 +0200
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.2.3-0ubuntu6+6.0trisquel1 
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic]
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -2.4 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.4 (--)

There is a missing feature for pipes created with mode OPEN_BOTH:

(use-modules (ice-9 popen))
(use-modules (rnrs io ports))

(let ((p (open-pipe "md5sum" OPEN_BOTH)))
  (put-string p "hello")
  (let ((x (get-string-all p)))
    (close-pipe p)
    x))

This code deadlocks in get-string-all because md5sum, like other
filters, keeps waiting for input until the pipe's output port is
closed.

The output port can't be closed without closing the input port too,
because an I/O pipe is a soft port that doesn't store the 2 ports
returned by open-process, but a thunk which closes both ports.

This is now possible with the new procedure close-pipe-output:

(let ((p (open-pipe "md5sum" OPEN_BOTH)))
  (put-string p "hello")
  (close-pipe-output p)
  (let ((x (get-string-all p)))
    (close-pipe p)
    x))
;; => "5d41402abc4b2a76b9719d911017c592  -\n"

The intention is to make a backwards compatible and minimal change
that makes it possible to write to and read from pipes for filters
like md5sum without temporary files.

Changes involved:

* module/ice-9/popen.scm: Define a weak hash-table for mapping I/O pipes to
  their output ports, change make-rw-port to use it, define the
  close-pipe-output procedure and export it.

* doc/ref/posix.texi: Add documentation for close-pipe-output.

On garbage collection the new hash-table is updated as expected:

scheme@(ice-9 popen)> rw/w-table
$3 = #<weak-key-hash-table 8b8a930 0/31>
scheme@(ice-9 popen)> (define p (open-pipe "md5sum" OPEN_BOTH))
scheme@(ice-9 popen)> rw/w-table
$4 = #<weak-key-hash-table 8b8a930 1/31>
scheme@(ice-9 popen)> (set! p #f)
scheme@(ice-9 popen)> (gc)
scheme@(ice-9 popen)> rw/w-table
$5 = #<weak-key-hash-table 8b8a930 0/31>

Maybe there is a better name for the new procedure.
---
 doc/ref/posix.texi     |    6 ++++++
 module/ice-9/popen.scm |   39 +++++++++++++++++++++++++++++----------
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index b3a6a04..f0c6ca1 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -2312,6 +2312,12 @@ terminate, and return the wait status code.  The status is as per
 (@pxref{Processes})
 @end deffn
 
+@deffn {Scheme Procedure} close-pipe-output port
+Close the output port of a pipe created by @code{open-pipe} with
+mode @code{OPEN_BOTH}, and leave the input port open.  Return `#t' if
+the port is closed successfully or `#f' if it was already closed.
+@end deffn
+
 @sp 1
 @code{waitpid WAIT_ANY} should not be used when pipes are open, since
 it can reap a pipe's child process, causing an error from a subsequent
diff --git a/module/ice-9/popen.scm b/module/ice-9/popen.scm
index 7d0549e..2b014c5 100644
--- a/module/ice-9/popen.scm
+++ b/module/ice-9/popen.scm
@@ -18,22 +18,32 @@
 ;;;; 
 
 (define-module (ice-9 popen)
-  :export (port/pid-table open-pipe* open-pipe close-pipe open-input-pipe
-	   open-output-pipe open-input-output-pipe))
+  :export (port/pid-table open-pipe* open-pipe close-pipe close-pipe-output
+           open-input-pipe open-output-pipe open-input-output-pipe))
 
 (eval-when (load eval compile)
   (load-extension (string-append "libguile-" (effective-version))
                   "scm_init_popen"))
 
+;; a weak hash-table to store the write port of read-write pipes
+;; just to be able to retrieve it in close-pipe-output.
+(define rw/w-table (make-weak-key-hash-table 31))
+
 (define (make-rw-port read-port write-port)
-  (make-soft-port
-   (vector
-    (lambda (c) (write-char c write-port))
-    (lambda (s) (display s write-port))
-    (lambda () (force-output write-port))
-    (lambda () (read-char read-port))
-    (lambda () (close-port read-port) (close-port write-port)))
-   "r+"))
+  (letrec ((port (make-soft-port
+                  (vector
+                   (lambda (c) (write-char c write-port))
+                   (lambda (s) (display s write-port))
+                   (lambda () (force-output write-port))
+                   (lambda () (read-char read-port))
+                   (lambda ()
+                     (hashq-remove! rw/w-table port)
+                     (close-port read-port)
+                     (or (port-closed? write-port)
+                         (close-port write-port))))
+                  "r+")))
+    (hashq-set! rw/w-table port write-port)
+    port))
 
 ;; a guardian to ensure the cleanup is done correctly when
 ;; an open pipe is gc'd or a close-port is used.
@@ -106,6 +116,15 @@ information on how to interpret this value."
         (error "close-pipe: pipe not in table"))
     (close-process (cons p pid))))
 
+(define (close-pipe-output pipe)
+  "Closes the output port of a pipe created by @code{open-pipe} with
+mode @code{OPEN_BOTH}, and leaves the input port open.  Returns `#t' if
+it successfully closes the port or `#f' if it was already closed."
+  (let ((port (hashq-ref rw/w-table pipe)))
+    (unless port
+      (error "close-pipe-output: pipe not in table"))
+    (close-port port)))
+
 (define reap-pipes
   (lambda ()
     (let loop ((p (pipe-guardian)))
-- 
1.7.9.5






Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.503 (Entity 5.503)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Josep Portella Florit <jpf@HIDDEN>
Subject: bug#15228: Acknowledgement ([PATCH] Close output port of I/O pipes)
Message-ID: <handler.15228.B.13779378561056.ack <at> debbugs.gnu.org>
References: <1377937797.2030.5.camel@qwghlm>
X-Gnu-PR-Message: ack 15228
X-Gnu-PR-Package: guile
X-Gnu-PR-Keywords: patch
Reply-To: 15228 <at> debbugs.gnu.org
Date: Sat, 31 Aug 2013 08:31:04 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 bug-guile@HIDDEN

If you wish to submit further information on this problem, please
send it to 15228 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
15228: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D15228
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15228: [PATCH] Close output port of I/O pipes
Resent-From: Andy Wingo <wingo@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Tue, 21 Jun 2016 10:48:01 +0000
Resent-Message-ID: <handler.15228.B15228.146650607424059 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 15228
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: patch
To: Josep Portella Florit <jpf@HIDDEN>
Cc: 15228 <at> debbugs.gnu.org, guile-devel@HIDDEN
Received: via spool by 15228-submit <at> debbugs.gnu.org id=B15228.146650607424059
          (code B ref 15228); Tue, 21 Jun 2016 10:48:01 +0000
Received: (at 15228) by debbugs.gnu.org; 21 Jun 2016 10:47:54 +0000
Received: from localhost ([127.0.0.1]:48598 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bFJDl-0006Fy-UV
	for submit <at> debbugs.gnu.org; Tue, 21 Jun 2016 06:47:54 -0400
Received: from pb-sasl1.pobox.com ([64.147.108.66]:54932
 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wingo@HIDDEN>) id 1bFJDh-0006Fm-NX
 for 15228 <at> debbugs.gnu.org; Tue, 21 Jun 2016 06:47:51 -0400
Received: from sasl.smtp.pobox.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id 32A3D21FFA;
 Tue, 21 Jun 2016 06:47:46 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; s=sasl; bh=1dRu+Md9DRolO8utfvhorjOTAmI=; b=Yvb6L9
 UdZrFiXheprpntjliajYX8ViEOxfwSwGpCJeM+1isfVozNlLEI3JwntsBziCcofd
 4WusgC80NjxBRGBMFcGsnnQcTXe8Kt4IxyFI8zOT0aRbTpi+fVlRVXnslb7pdfwl
 Ofy6bHxdbTkyGAVzKg/O0IzEP+AwqFJf3J/98=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; q=dns; s=sasl; b=hSSx9zR5iz5alQ/2Cd5cqERHjbsG0bpX
 HAKT5j6W90HCciaSYL/0qqfh1/Sl4AzI8BPUlMPutDeO+DbCrCRQl34TQAJFmOnV
 H8j6qD0cvO4d63iict1kFDZdP9QNnjt68wiHsvi73/sbmbvVks+1j7qjY0i3k81j
 TcQmRZJFE/8=
Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id 2A4FD21FF9;
 Tue, 21 Jun 2016 06:47:46 -0400 (EDT)
Received: from clucks (unknown [88.160.190.192])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 2AA8321FF8;
 Tue, 21 Jun 2016 06:47:45 -0400 (EDT)
From: Andy Wingo <wingo@HIDDEN>
References: <1377937797.2030.5.camel@qwghlm>
Date: Tue, 21 Jun 2016 12:47:38 +0200
In-Reply-To: <1377937797.2030.5.camel@qwghlm> (Josep Portella Florit's message
 of "Sat, 31 Aug 2013 10:29:57 +0200")
Message-ID: <87eg7q3jjp.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Pobox-Relay-ID: 966ECC94-379D-11E6-8B44-C1836462E9F6-02397024!pb-sasl1.pobox.com
X-Spam-Score: -1.4 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.4 (-)

Hi :)

I dunno how much we should push this "processes are a single port"
abstraction.  In many ways for OPEN_BOTH pipes it's easier to deal with
an input and an output port and a PID instead of the pipe abstraction.
WDYT?  We could just expose `open-process' from (ice-9 popen) to start
with.  It would be good to allow other fd's or ports to map to the child
as well, e.g. stderr or any particular port; but I don't know what
interface we should expose.

Thoughts?

Andy

On Sat 31 Aug 2013 10:29, Josep Portella Florit <jpf@HIDDEN> writes:

> There is a missing feature for pipes created with mode OPEN_BOTH:
>
> (use-modules (ice-9 popen))
> (use-modules (rnrs io ports))
>
> (let ((p (open-pipe "md5sum" OPEN_BOTH)))
>   (put-string p "hello")
>   (let ((x (get-string-all p)))
>     (close-pipe p)
>     x))
>
> This code deadlocks in get-string-all because md5sum, like other
> filters, keeps waiting for input until the pipe's output port is
> closed.
>
> The output port can't be closed without closing the input port too,
> because an I/O pipe is a soft port that doesn't store the 2 ports
> returned by open-process, but a thunk which closes both ports.
>
> This is now possible with the new procedure close-pipe-output:
>
> (let ((p (open-pipe "md5sum" OPEN_BOTH)))
>   (put-string p "hello")
>   (close-pipe-output p)
>   (let ((x (get-string-all p)))
>     (close-pipe p)
>     x))
> ;; => "5d41402abc4b2a76b9719d911017c592  -\n"
>
> The intention is to make a backwards compatible and minimal change
> that makes it possible to write to and read from pipes for filters
> like md5sum without temporary files.
>
> Changes involved:
>
> * module/ice-9/popen.scm: Define a weak hash-table for mapping I/O pipes to
>   their output ports, change make-rw-port to use it, define the
>   close-pipe-output procedure and export it.
>
> * doc/ref/posix.texi: Add documentation for close-pipe-output.
>
> On garbage collection the new hash-table is updated as expected:
>
> scheme@(ice-9 popen)> rw/w-table
> $3 = #<weak-key-hash-table 8b8a930 0/31>
> scheme@(ice-9 popen)> (define p (open-pipe "md5sum" OPEN_BOTH))
> scheme@(ice-9 popen)> rw/w-table
> $4 = #<weak-key-hash-table 8b8a930 1/31>
> scheme@(ice-9 popen)> (set! p #f)
> scheme@(ice-9 popen)> (gc)
> scheme@(ice-9 popen)> rw/w-table
> $5 = #<weak-key-hash-table 8b8a930 0/31>
>
> Maybe there is a better name for the new procedure.
> ---
>  doc/ref/posix.texi     |    6 ++++++
>  module/ice-9/popen.scm |   39 +++++++++++++++++++++++++++++----------
>  2 files changed, 35 insertions(+), 10 deletions(-)
>
> diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
> index b3a6a04..f0c6ca1 100644
> --- a/doc/ref/posix.texi
> +++ b/doc/ref/posix.texi
> @@ -2312,6 +2312,12 @@ terminate, and return the wait status code.  The status is as per
>  (@pxref{Processes})
>  @end deffn
>  
> +@deffn {Scheme Procedure} close-pipe-output port
> +Close the output port of a pipe created by @code{open-pipe} with
> +mode @code{OPEN_BOTH}, and leave the input port open.  Return `#t' if
> +the port is closed successfully or `#f' if it was already closed.
> +@end deffn
> +
>  @sp 1
>  @code{waitpid WAIT_ANY} should not be used when pipes are open, since
>  it can reap a pipe's child process, causing an error from a subsequent
> diff --git a/module/ice-9/popen.scm b/module/ice-9/popen.scm
> index 7d0549e..2b014c5 100644
> --- a/module/ice-9/popen.scm
> +++ b/module/ice-9/popen.scm
> @@ -18,22 +18,32 @@
>  ;;;; 
>  
>  (define-module (ice-9 popen)
> -  :export (port/pid-table open-pipe* open-pipe close-pipe open-input-pipe
> -	   open-output-pipe open-input-output-pipe))
> +  :export (port/pid-table open-pipe* open-pipe close-pipe close-pipe-output
> +           open-input-pipe open-output-pipe open-input-output-pipe))
>  
>  (eval-when (load eval compile)
>    (load-extension (string-append "libguile-" (effective-version))
>                    "scm_init_popen"))
>  
> +;; a weak hash-table to store the write port of read-write pipes
> +;; just to be able to retrieve it in close-pipe-output.
> +(define rw/w-table (make-weak-key-hash-table 31))
> +
>  (define (make-rw-port read-port write-port)
> -  (make-soft-port
> -   (vector
> -    (lambda (c) (write-char c write-port))
> -    (lambda (s) (display s write-port))
> -    (lambda () (force-output write-port))
> -    (lambda () (read-char read-port))
> -    (lambda () (close-port read-port) (close-port write-port)))
> -   "r+"))
> +  (letrec ((port (make-soft-port
> +                  (vector
> +                   (lambda (c) (write-char c write-port))
> +                   (lambda (s) (display s write-port))
> +                   (lambda () (force-output write-port))
> +                   (lambda () (read-char read-port))
> +                   (lambda ()
> +                     (hashq-remove! rw/w-table port)
> +                     (close-port read-port)
> +                     (or (port-closed? write-port)
> +                         (close-port write-port))))
> +                  "r+")))
> +    (hashq-set! rw/w-table port write-port)
> +    port))
>  
>  ;; a guardian to ensure the cleanup is done correctly when
>  ;; an open pipe is gc'd or a close-port is used.
> @@ -106,6 +116,15 @@ information on how to interpret this value."
>          (error "close-pipe: pipe not in table"))
>      (close-process (cons p pid))))
>  
> +(define (close-pipe-output pipe)
> +  "Closes the output port of a pipe created by @code{open-pipe} with
> +mode @code{OPEN_BOTH}, and leaves the input port open.  Returns `#t' if
> +it successfully closes the port or `#f' if it was already closed."
> +  (let ((port (hashq-ref rw/w-table pipe)))
> +    (unless port
> +      (error "close-pipe-output: pipe not in table"))
> +    (close-port port)))
> +
>  (define reap-pipes
>    (lambda ()
>      (let loop ((p (pipe-guardian)))




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15228: [PATCH] Close output port of I/O pipes
Resent-From: Andy Wingo <wingo@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Mon, 27 Jun 2016 08:06:01 +0000
Resent-Message-ID: <handler.15228.B15228.146701471832069 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 15228
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: patch
To: 15228 <at> debbugs.gnu.org
Received: via spool by 15228-submit <at> debbugs.gnu.org id=B15228.146701471832069
          (code B ref 15228); Mon, 27 Jun 2016 08:06:01 +0000
Received: (at 15228) by debbugs.gnu.org; 27 Jun 2016 08:05:18 +0000
Received: from localhost ([127.0.0.1]:57443 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bHRXh-0008L9-EB
	for submit <at> debbugs.gnu.org; Mon, 27 Jun 2016 04:05:18 -0400
Received: from pb-sasl1.pobox.com ([64.147.108.66]:50142
 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wingo@HIDDEN>) id 1bHRXf-0008L0-5e
 for 15228 <at> debbugs.gnu.org; Mon, 27 Jun 2016 04:05:15 -0400
Received: from sasl.smtp.pobox.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id C115F205A3
 for <15228 <at> debbugs.gnu.org>; Mon, 27 Jun 2016 04:05:14 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; s=sasl; bh=NP20nsFxSx92JFk6sE7OOSjYDGs=; b=XVqlFK
 ZMNRhKF29ld1P4mmbvxNUjQw+9w4Zj1/MgM3EBPsj8uyzhyhzmiWRoeZ24bnSz0M
 oUoRA8z7weNrFPJHJKDdkyz97AvhKy94afopqc7WvWgxICSlsbqimldFdhpq+pHy
 C2H0mSw04fiGlNgkjRCBXSeDlrP3zIVupXTJQ=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject
 :references:date:in-reply-to:message-id:mime-version
 :content-type; q=dns; s=sasl; b=kzT25+lBzPVfQpjVqm/zgGP0NKJhM9jO
 aovSWDP9RfYc2pT2KdStAR0nBgpARHQBEb3S0JIYjrKQcYEu8Tq4Tj140Gd5AM7C
 rxtfgkppWpX+DKkNQ8hdNt5Q8TnN4exHCov5BGOVEG7yE9JQQUnG2O7DItN1WKIB
 KpGp+pt9KBg=
Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id B9437205A2
 for <15228 <at> debbugs.gnu.org>; Mon, 27 Jun 2016 04:05:14 -0400 (EDT)
Received: from clucks (unknown [88.160.190.192])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 07DE6205A1
 for <15228 <at> debbugs.gnu.org>; Mon, 27 Jun 2016 04:05:13 -0400 (EDT)
From: Andy Wingo <wingo@HIDDEN>
References: <628d9c7d-e7d5-6e55-1361-316629db8b4b@HIDDEN>
 <8760sxb74x.fsf@HIDDEN>
Date: Mon, 27 Jun 2016 10:05:06 +0200
In-Reply-To: <8760sxb74x.fsf@HIDDEN> (Andy Wingo's message of "Sat, 25 Jun
 2016 17:49:50 +0200")
Message-ID: <87ziq783bh.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Pobox-Relay-ID: E0AE17A2-3C3D-11E6-BCF6-C1836462E9F6-02397024!pb-sasl1.pobox.com
X-Spam-Score: -1.0 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

[bouncing this back to debbugs]

On Sat 25 Jun 2016 17:49, Andy Wingo <wingo@HIDDEN> writes:

> On Sat 25 Jun 2016 15:51, Josep Portella Florit <jpf@HIDDEN> writes:
>
>>> I dunno how much we should push this "processes are a single port"
>>> abstraction.  In many ways for OPEN_BOTH pipes it's easier to deal with
>>> an input and an output port and a PID instead of the pipe abstraction.
>>> WDYT?  We could just expose `open-process' from (ice-9 popen) to start
>>> with.  It would be good to allow other fd's or ports to map to the child
>>> as well, e.g. stderr or any particular port; but I don't know what
>>> interface we should expose.
>>
>> Since patching was inconvenient for me, I eventually used:
>>
>> (use-modules ((ice-9 popen) #:select (open-process)))
>>
>> Which works even though `open-process` is not exported.
>
> Note that this behavior of #:select is a bug.  We won't remove it in
> stable-2.0 but we have removed it in master.
>
>> For me, exporting `open-process` and documenting it would be enough.
>
> Fine with me, many people have asked for this at this point.  I guess
> that's the next step for this bug.
>
>> I also like the Racket interface to processes:
>> <https://docs.racket-lang.org/reference/subprocess.html>
>> (I've mostly used the `process` procedure.)
>
> Duly noted!  The more we steal from Racket, the better Guile will be :)
>
> Andy




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15228: making open-process public
References: <1377937797.2030.5.camel@qwghlm>
In-Reply-To: <1377937797.2030.5.camel@qwghlm>
Resent-From: Amirouche Boubekki <amirouche@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Sat, 03 Sep 2016 07:34:02 +0000
Resent-Message-ID: <handler.15228.B15228.14728880177072 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 15228
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: patch
To: 15228 <at> debbugs.gnu.org
Received: via spool by 15228-submit <at> debbugs.gnu.org id=B15228.14728880177072
          (code B ref 15228); Sat, 03 Sep 2016 07:34:02 +0000
Received: (at 15228) by debbugs.gnu.org; 3 Sep 2016 07:33:37 +0000
Received: from localhost ([127.0.0.1]:48240 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bg5SK-0001q0-WE
	for submit <at> debbugs.gnu.org; Sat, 03 Sep 2016 03:33:37 -0400
Received: from relay3-d.mail.gandi.net ([217.70.183.195]:36622)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <amirouche@HIDDEN>) id 1bg5SJ-0001pr-Aa
 for 15228 <at> debbugs.gnu.org; Sat, 03 Sep 2016 03:33:35 -0400
Received: from mfilter20-d.gandi.net (mfilter20-d.gandi.net [217.70.178.148])
 by relay3-d.mail.gandi.net (Postfix) with ESMTP id 2BC94A80C7
 for <15228 <at> debbugs.gnu.org>; Sat,  3 Sep 2016 09:33:34 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at mfilter20-d.gandi.net
Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195])
 by mfilter20-d.gandi.net (mfilter20-d.gandi.net [::ffff:10.0.15.180])
 (amavisd-new, port 10024)
 with ESMTP id qhDPqNtxrcZF for <15228 <at> debbugs.gnu.org>;
 Sat,  3 Sep 2016 09:33:32 +0200 (CEST)
X-Originating-IP: 10.58.1.148
Received: from webmail.gandi.net (webmail8-d.mgt.gandi.net [10.58.1.148])
 (Authenticated sender: amirouche@HIDDEN)
 by relay3-d.mail.gandi.net (Postfix) with ESMTPA id C9519A80C8
 for <15228 <at> debbugs.gnu.org>; Sat,  3 Sep 2016 09:33:32 +0200 (CEST)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII;
 format=flowed
Content-Transfer-Encoding: 7bit
Date: Sat, 03 Sep 2016 09:33:32 +0200
From: Amirouche Boubekki <amirouche@HIDDEN>
Message-ID: <145cea679b38ca9de4e8b1c9f2213622@HIDDEN>
X-Sender: amirouche@HIDDEN
User-Agent: Roundcube Webmail/1.1.2
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

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?




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15228: making open-process public
Resent-From: Andy Wingo <wingo@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Tue, 28 Feb 2017 09:59:01 +0000
Resent-Message-ID: <handler.15228.B15228.148827591131675 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 15228
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: patch
To: Amirouche Boubekki <amirouche@HIDDEN>
Cc: 15228 <at> debbugs.gnu.org
Received: via spool by 15228-submit <at> debbugs.gnu.org id=B15228.148827591131675
          (code B ref 15228); Tue, 28 Feb 2017 09:59:01 +0000
Received: (at 15228) by debbugs.gnu.org; 28 Feb 2017 09:58:31 +0000
Received: from localhost ([127.0.0.1]:59076 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1cieYA-0008Eo-V4
	for submit <at> debbugs.gnu.org; Tue, 28 Feb 2017 04:58:31 -0500
Received: from pb-sasl1.pobox.com ([64.147.108.66]:64881
 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wingo@HIDDEN>) id 1cieY9-0008Ee-Dr
 for 15228 <at> debbugs.gnu.org; Tue, 28 Feb 2017 04:58:29 -0500
Received: from sasl.smtp.pobox.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id 22C4B5F864;
 Tue, 28 Feb 2017 04:58:27 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; s=sasl; bh=upo6c4N4TneJCx5dIjIgx2DiGUQ=; b=tWtTnS
 9S6+e/mz+MKbMoSfX0AGjDRwDmIwjA7AeiZHw4JyOCGOWEMMh6R5ryFy5drJmGHy
 v3u5s6kMthXO3zhsT4Onld7srQOeahRd/P97S1gTgD/J2Z7YRgt/A9P8+4sc5Pu5
 O0rYlVVektjeedKab+sxd2YkqWIQLUI7fyFAk=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; q=dns; s=sasl; b=ff4SU9CNcYIQvMIKq/yH2CDXYr44Kdh5
 ygouFtZZWgPc+9BptLT84iVNACUilSR5PVKK9ObIEhhqYIS0oqyg3CyQH1J23VjW
 HI4Oq15LEUP816IWFADsxhK56C6jXYfe1jBS5WGnkxAwF6mA0wqanjn1PBFVJH42
 7P9T4Zhy2IY=
Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id 1ADFF5F863;
 Tue, 28 Feb 2017 04:58:27 -0500 (EST)
Received: from clucks (unknown [88.160.190.192])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 1DF615F861;
 Tue, 28 Feb 2017 04:58:26 -0500 (EST)
From: Andy Wingo <wingo@HIDDEN>
References: <1377937797.2030.5.camel@qwghlm>
 <145cea679b38ca9de4e8b1c9f2213622@HIDDEN>
Date: Tue, 28 Feb 2017 10:58:18 +0100
In-Reply-To: <145cea679b38ca9de4e8b1c9f2213622@HIDDEN> (Amirouche
 Boubekki's message of "Sat, 03 Sep 2016 09:33:32 +0200")
Message-ID: <87bmtmprgl.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Pobox-Relay-ID: 72CCD4BE-FD9C-11E6-9DB4-CDEC6462E9F6-02397024!pb-sasl1.pobox.com
X-Spam-Score: 0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)

On Sat 03 Sep 2016 09:33, Amirouche Boubekki <amirouche@HIDDEN> writes:

>> We could just expose `open-process' from (ice-9 popen) to start with.
>
> 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?

Yep!  Let's just do this.  Would you mind sending a patch.

Andy




Message sent to bug-guile@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15228: making open-process public
Resent-From: Amirouche <amirouche@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-guile@HIDDEN
Resent-Date: Sun, 05 Mar 2017 20:42:02 +0000
Resent-Message-ID: <handler.15228.B15228.148874651627091 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 15228
X-GNU-PR-Package: guile
X-GNU-PR-Keywords: patch
To: 15228 <at> debbugs.gnu.org
Received: via spool by 15228-submit <at> debbugs.gnu.org id=B15228.148874651627091
          (code B ref 15228); Sun, 05 Mar 2017 20:42:02 +0000
Received: (at 15228) by debbugs.gnu.org; 5 Mar 2017 20:41:56 +0000
Received: from localhost ([127.0.0.1]:41365 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ckcya-00072t-8L
	for submit <at> debbugs.gnu.org; Sun, 05 Mar 2017 15:41:56 -0500
Received: from relay4-d.mail.gandi.net ([217.70.183.196]:38079)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <amirouche@HIDDEN>) id 1ckcyY-00072j-5N
 for 15228 <at> debbugs.gnu.org; Sun, 05 Mar 2017 15:41:54 -0500
Received: from [IPv6:2a01:e35:2ef3:d930:1d63:a765:189:27df] (unknown
 [IPv6:2a01:e35:2ef3:d930:1d63:a765:189:27df])
 (Authenticated sender: amirouche@HIDDEN)
 by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id AB3501720AC
 for <15228 <at> debbugs.gnu.org>; Sun,  5 Mar 2017 21:41:52 +0100 (CET)
References: <1377937797.2030.5.camel@qwghlm>
 <145cea679b38ca9de4e8b1c9f2213622@HIDDEN>
From: Amirouche <amirouche@HIDDEN>
Message-ID: <450ba7d0-800e-3c65-4d32-e9b40747cd64@HIDDEN>
Date: Sun, 5 Mar 2017 21:41:56 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.7.0
MIME-Version: 1.0
In-Reply-To: <145cea679b38ca9de4e8b1c9f2213622@HIDDEN>
Content-Type: multipart/mixed; boundary="------------7374C500BE0D7988597430D2"
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

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 <amirouche@HIDDEN>
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 <amirouche@HIDDEN>
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--





Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.