unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Amirouche <amirouche@hypermove.net>
To: 15228@debbugs.gnu.org
Subject: bug#15228: making open-process public
Date: Sun, 5 Mar 2017 21:41:56 +0100	[thread overview]
Message-ID: <450ba7d0-800e-3c65-4d32-e9b40747cd64@hypermove.net> (raw)
In-Reply-To: <145cea679b38ca9de4e8b1c9f2213622@hypermove.net>

[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]

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?
>
>
>


[-- Attachment #2: 0002-make-open-process-public-in-ice-9-popen.patch --]
[-- Type: text/x-patch, Size: 4399 bytes --]

From 997e521e2368c771822b9741e47850665f7715f1 Mon Sep 17 00:00:00 2001
From: Amirouche <amirouche@hypermove.net>
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


[-- Attachment #3: 0001-whitespace-cleanup.patch --]
[-- Type: text/x-patch, Size: 1666 bytes --]

From ae9587457b502234fc137644a12bbd754e6fdc0c Mon Sep 17 00:00:00 2001
From: Amirouche <amirouche@hypermove.net>
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


  parent reply	other threads:[~2017-03-05 20:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-31  8:29 bug#15228: [PATCH] Close output port of I/O pipes Josep Portella Florit
2016-06-21 10:47 ` Andy Wingo
2016-09-03  7:33 ` bug#15228: making open-process public Amirouche Boubekki
2017-02-28  9:58   ` Andy Wingo
2017-03-05 20:41   ` Amirouche [this message]
2021-06-02  5:45 ` bug#15228: can this be closed ? Adriano Peluso

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=450ba7d0-800e-3c65-4d32-e9b40747cd64@hypermove.net \
    --to=amirouche@hypermove.net \
    --cc=15228@debbugs.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).