From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: doc popen Date: Tue, 28 Dec 2004 11:32:10 +1100 Message-ID: <87r7lbmfed.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1104193960 5186 80.91.229.6 (28 Dec 2004 00:32:40 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 28 Dec 2004 00:32:40 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Dec 28 01:32:35 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Cj5Hv-0001wc-00 for ; Tue, 28 Dec 2004 01:32:35 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Cj5Sj-0000BA-9P for guile-devel@m.gmane.org; Mon, 27 Dec 2004 19:43:45 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Cj5Sc-0000Ak-8b for guile-devel@gnu.org; Mon, 27 Dec 2004 19:43:38 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Cj5Sb-0000AB-5I for guile-devel@gnu.org; Mon, 27 Dec 2004 19:43:37 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Cj5Sa-00009q-VA for guile-devel@gnu.org; Mon, 27 Dec 2004 19:43:37 -0500 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Cj5He-0005ze-C2 for guile-devel@gnu.org; Mon, 27 Dec 2004 19:32:18 -0500 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-7.1) with ESMTP id iBS0WGHn015555 for ; Tue, 28 Dec 2004 11:32:16 +1100 Original-Received: from localhost (ppp2223.dyn.pacific.net.au [61.8.34.35]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-7.1) with ESMTP id iBS0WEIl014401 for ; Tue, 28 Dec 2004 11:32:15 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1Cj5HW-0000pk-00; Tue, 28 Dec 2004 11:32:10 +1100 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:4595 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:4595 Bit of a revision of the popen module docs. The description of current ports inherited is new. The WAIT_ANY in the open-input-pipe example was not good, it makes close-pipe bomb (if that function is used). 6.2.10 Pipes ------------ The following procedures are similar to the `popen' and `pclose' system routines. The code is in a separate "popen" module: (use-modules (ice-9 popen)) -- Scheme Procedure: open-pipe command modes Execute the shell COMMAND (a string) in a subprocess. A pipe to the process is created and returned. MODES specifies whether an input or output pipe to the process is created: it should be one of the two following values. -- Variable: OPEN_READ -- Variable: OPEN_WRITE For an input pipe, in the child the standard output is the pipe and standard input is inherited from Guile's `current-input-port'. For an output pipe, in the child the standard input is the pipe and standard output is inherited from Guile's `current-output-port'. In both cases the standard error in the child is inherited from `current-error-port' (*note Default Ports::). If those `current-X-ports' are not files of some kind, and hence don't have file descriptors for the child, then `/dev/null' is used instead. -- Scheme Procedure: open-input-pipe command Equivalent to `open-pipe' with mode `OPEN_READ'. (let* ((port (open-input-pipe "date")) (str (read-line port))) (close-pipe port) str) => "Mon Mar 11 20:10:44 GMT 2002" -- Scheme Procedure: open-output-pipe command Equivalent to `open-pipe' with mode `OPEN_WRITE'. (let ((port (open-output-pipe "lpr"))) (display "Something for the line printer.\n" port) (if (not (eqv? 0 (status:exit-val (close-pipe port)))) (error "Cannot print"))) -- Scheme Procedure: close-pipe port Close a pipe created by `open-pipe', wait for the process to terminate, and return the wait status code. The status is as per `waitpid' and can be decoded with `status:exit-val' etc (*note Processes::) `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 `close-pipe'. `close-port' (*note Closing::) can close a pipe, but it doesn't do anything with the child process. The garbage collector will close a pipe no longer in use, and reap the child process with `waitpid'. If the child hasn't yet terminated the garbage collector doesn't block, but instead checks again in the next GC. Many systems have per-user and system-wide limits on the number of processes, and a system-wide limit on the number of pipes, so it's worth closing a pipe explicitly once it's longer needed, rather than letting the garbage collector pick it up at some later time. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel