From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jeff Mickey Newsgroups: gmane.lisp.guile.bugs Subject: bug#24680: Documentation / Behavior of open-pipe* with stderr Date: Wed, 12 Oct 2016 16:18:13 -0700 Message-ID: <87fuo12m2y.fsf@purestorage.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1476314742 17024 195.159.176.226 (12 Oct 2016 23:25:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 12 Oct 2016 23:25:42 +0000 (UTC) To: 24680@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Thu Oct 13 01:25:38 2016 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 1buStu-000334-Ew for guile-bugs@m.gmane.org; Thu, 13 Oct 2016 01:25:30 +0200 Original-Received: from localhost ([::1]:36380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buStr-0004m7-MZ for guile-bugs@m.gmane.org; Wed, 12 Oct 2016 19:25:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buSnj-0008H1-JU for bug-guile@gnu.org; Wed, 12 Oct 2016 19:19:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buSnf-0002Bm-PV for bug-guile@gnu.org; Wed, 12 Oct 2016 19:19:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47344) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buSne-0002BZ-IS for bug-guile@gnu.org; Wed, 12 Oct 2016 19:19:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1buSne-0004Wo-Dw for bug-guile@gnu.org; Wed, 12 Oct 2016 19:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jeff Mickey Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 12 Oct 2016 23:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24680 X-GNU-PR-Package: guile X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.147631432317373 (code B ref -1); Wed, 12 Oct 2016 23:19:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Oct 2016 23:18:43 +0000 Original-Received: from localhost ([127.0.0.1]:53534 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1buSnK-0004W9-Px for submit@debbugs.gnu.org; Wed, 12 Oct 2016 19:18:42 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45042) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1buSnJ-0004Vt-57 for submit@debbugs.gnu.org; Wed, 12 Oct 2016 19:18:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buSnC-00023I-FC for submit@debbugs.gnu.org; Wed, 12 Oct 2016 19:18:35 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:44087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buSnC-00022t-9O for submit@debbugs.gnu.org; Wed, 12 Oct 2016 19:18:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buSn9-0007kl-N0 for bug-guile@gnu.org; Wed, 12 Oct 2016 19:18:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buSn5-00020x-Cw for bug-guile@gnu.org; Wed, 12 Oct 2016 19:18:30 -0400 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:57465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buSn3-0001x6-WC for bug-guile@gnu.org; Wed, 12 Oct 2016 19:18:27 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 34BE820516; Wed, 12 Oct 2016 19:18:15 -0400 (EDT) Original-Received: from frontend1 ([10.202.2.160]) by compute2.internal (MEProxy); Wed, 12 Oct 2016 19:18:15 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=codemac.net; h= content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=Epj HCfGpJ//6vymXgvwt3lEt+a0=; b=lfapFJCQkz3y+kPfr2tACoAzafkz+AvA/bJ 2ce9fuknUu3Xi7kAOzEzZFlgnd3pI0PapQp1URXe75u7nJPeT/xnkp5xGfiXKQ12 Sp6xMqzyUBLxqDmjSTyN6/4qxqo1sLhcjyhQa0yVsxh2mF5HpXfXqoc0LwQerBXf nAl/HfuU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=EpjHCfGpJ//6vymXgvwt3lEt+a0=; b=EaZ33 awF1zgAELXpJG2pnv+rlqFo0tMyW+wVMDzu00vvFKsDAAE5EEy10ZzGPzsPTotLL TL70pO9YZYzy5XyVV3j+dPgCFJLwXilLd2z4dR/aK9r2HXYzqKhuFCqQPEtrFjUw nbjsgy3rdAkotle5ZVbqZc4ruJ+6VDv+hd3WOY= X-Sasl-enc: vhdmqlqgDxIiv9X7xp198mYqKHYh+WBa1++NEHrQ4lCz 1476314294 Original-Received: from novaria.codemac.net (unknown [64.84.70.252]) by mail.messagingengine.com (Postfix) with ESMTPA id B5F02F2985 for ; Wed, 12 Oct 2016 19:18:14 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:8429 Archived-At: Hi! So, I like to build up programs by tieing together a few different programs, and then replacing parts where I reimplement features in simpler ways. Currently, I have a piece of guile code that calls out to dd, and I wanted to capture the stderr and print it if dd failed to run successfully. If it ran successfully, I just wanted to swallow it. I read the following from the guile Info page 7.2.10 Pipes under the procedure documentation for open-pipe*: For an input pipe, the child=E2=80=99s standard output is the pipe and standard input is inherited from =E2=80=98current-input-port=E2=80=99. F= or an output pipe, the child=E2=80=99s standard input is the pipe and standard output is inherited from =E2=80=98current-output-port=E2=80=99. In all c= ases cases the child=E2=80=99s standard error is inherited from =E2=80=98current-err= or-port=E2=80=99 (*note Default Ports::). So, in my assumption, I should be able to use parameterize on current-error-port, and set it to a string port. Here is some test code: (use-modules (ice-9 popen)) =20=20 (define (port-copy dst src) (let ((c (read-char src))) (if (eof-object? c) dst (begin (write-char c dst) (port-copy dst src))))) =20=20 (define (print-outs one two) (format #t "what was stored in stdout:~%~a~%~%" (get-output= -string os)) (format #t "what was stored in stderr:~%~a~%~%" (get-output= -string es))) =20=20 (let ((os (open-output-string)) (es (open-output-string))) (parameterize ((current-error-port es)) (let ((rp (open-pipe* OPEN_BOTH "logger" "-s" "help me i'm stderr"))) (port-copy os rp) (status:exit-val (close-pipe rp)))) (print-outs os es)) =20=20 (let ((os (open-output-string)) (es (open-output-string))) (parameterize ((current-error-port es)) (let ((rp (open-pipe* OPEN_BOTH "echo" "help me i'm stdout"))) (port-copy os rp) (status:exit-val (close-pipe rp)))) (print-outs os es)) This, notably, is unable to print stderr. I tried changing the parameterize to a call to set-current-error-port, but this didn't work either, same results where it's blank. So, clearly, something is wrong. Then I looked at the source of posix.c & strports.c & fports.h, and it looks like string ports cannot be used for open-pipe*. 6.14.8 Default Ports for Input, Output and Errors do not call this out. I haven't figured out how to fix it yet, but I think it'd be great if string/byte ports could be used everywhere, including for stdout/stdin. Seems like we could check if the in/out/error ports are fd's or not like currently (line 1388 of posix.c) but in the else case set up some type of thread (or forked process) that goes off and copies whatever comes out of the fd into a byte or string port. I don't know enough about the guile C implementation to make more concrete suggestions. Thanks in advance. At the least, I feel like the documentation for open-pipe* and the Default Ports could be improved significantly. // codemac