From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Christopher Allan Webber Newsgroups: gmane.lisp.guile.user Subject: Pipes and processes, stdin, stdout and stderr Date: Mon, 13 Apr 2015 19:17:41 -0500 Message-ID: <873842yahs.fsf@earlgrey.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1429026628 17274 80.91.229.3 (14 Apr 2015 15:50:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 14 Apr 2015 15:50:28 +0000 (UTC) To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Apr 14 17:50:24 2015 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Yi36V-0008A9-U2 for guile-user@m.gmane.org; Tue, 14 Apr 2015 17:50:24 +0200 Original-Received: from localhost ([::1]:56634 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yi36V-0008UU-7d for guile-user@m.gmane.org; Tue, 14 Apr 2015 11:50:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yi36M-0008UP-FF for guile-user@gnu.org; Tue, 14 Apr 2015 11:50:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yi36E-00066a-Bq for guile-user@gnu.org; Tue, 14 Apr 2015 11:50:14 -0400 Original-Received: from dustycloud.org ([50.116.34.160]:56635) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yi36E-00063Y-7h for guile-user@gnu.org; Tue, 14 Apr 2015 11:50:06 -0400 Original-Received: from earlgrey.lan (localhost [127.0.0.1]) by dustycloud.org (Postfix) with ESMTPS id 8836E265FE for ; Tue, 14 Apr 2015 11:50:04 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 50.116.34.160 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:11796 Archived-At: Hello all, Last night I was trying to do the equivalent of this: bash$ echo "foo" | sha512sum in guile. But I was unable to find a clear way to do it. I tried something like: (let* ((port (open-pipe* OPEN_BOTH "sha256sum" "--binary"))) (display "test me\n" port) (force-output port) (let ((result (drain-input port))) (close-port port) (car (string-split result #\space)))) Unfortunately, this just hangs forever at the drain-input. I get the same issue if I do (read-line port). What I expected was that Guile would provide a way to access stdin, stdout, stderr in a process as separate ports. Python provides an API more or less like this: >>> from subprocess import Popen, PIPE >>> proc = Popen("sha256sum", stdin=PIPE, stdout=PIPE) >>> proc.stdin.write(b"foo") 3 >>> proc.stdin.close() >>> proc.stdout.read() b'2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae -\n' It looks like in the past there were discussions about doing something similar: http://comments.gmane.org/gmane.lisp.guile.user/9300 It might be really nice if there was a way to access stdin, stdout, and stderr as separate ports. I might be willing to write some code for it, if someone could point me in the right direction. But I really don't know where to look. Is there a way to do this that I don't know? Thanks for the help! - Chris