From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Thomas Danckaert Newsgroups: gmane.lisp.guile.user Subject: capture stdout and stderr Date: Thu, 24 May 2018 10:10:22 +0200 (CEST) Message-ID: <20180524.101022.981642295161978602.post@thomasdanckaert.be> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1527149342 15743 195.159.176.226 (24 May 2018 08:09:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 24 May 2018 08:09:02 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu May 24 10:08:58 2018 Return-path: Envelope-to: guile-user@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 1fLlIv-0003yT-PC for guile-user@m.gmane.org; Thu, 24 May 2018 10:08:57 +0200 Original-Received: from localhost ([::1]:37093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLlL2-0000RW-VI for guile-user@m.gmane.org; Thu, 24 May 2018 04:11:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLlKg-0000RO-3w for guile-user@gnu.org; Thu, 24 May 2018 04:10:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLlKc-00005G-45 for guile-user@gnu.org; Thu, 24 May 2018 04:10:46 -0400 Original-Received: from s02.spamexperts.axc.nl ([185.182.56.112]:52253) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLlKb-0008Uw-TI for guile-user@gnu.org; Thu, 24 May 2018 04:10:42 -0400 Original-Received: from vserver42.axc.nl ([185.182.56.92]) by s02.spamexperts.axc.nl with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1fLlKP-0006tT-E1 for guile-user@gnu.org; Thu, 24 May 2018 10:10:35 +0200 Original-Received: from mail.axc.nl ([185.182.56.42]:58870) by vserver42.axc.nl with esmtp (Exim 4.91) (envelope-from ) id 1fLlKK-0001MJ-U9 for guile-user@gnu.org; Thu, 24 May 2018 10:10:29 +0200 X-Mailer: Mew version 6.7 on Emacs 25.3 / Mule 6.0 (HANACHIRUSATO) PrimaryMX: Accepted email from trusted host. Hint: This skips spam scanning so make sure other host is not vulnerable X-Relay-Host: 185.182.56.42 SpamTally: Final spam score: 0 X-Originating-IP: 185.182.56.92 X-SpamExperts-Domain: vserver42.axc.nl X-SpamExperts-Username: 185.182.56.92 Authentication-Results: spamexperts.axc.nl; auth=pass smtp.auth=185.182.56.92@vserver42.axc.nl X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.16) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5n18K1TnQyYj1VMnDfQpNq5602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO587IEwkeqVIekXgxeoWskaUFzM/DcqXjylVQRFCEtTnSCpnRUoY+mSIscxrodGN6wTJ sjWw5+0eZIpQIcK9yrTOdWG4cwy4eb7cCNwhEPxIE/bGKkWjX0vBrTNL7qKCVSRh5bRscFlNvvbM elN97t21umcuh1GvkHLZ8OnZHyNWPMpNXxpZuiYRs23iVM0el8g6NTTd2ar8H7FVMTvlrjiix59s TWOZYSnnMjQ31wvFVPTxUfTKKOeFu/oqiIZGN60Pz3HXU5UthAW1bQwZ4UfrB0nPx35TbLrGoP6k 1WjRF8VpymDAm51vSeaku+X2qYfWdHzoB2yW92yX6zvRr8FQuJ490qsBcQ5yLtdZaWkKBZ6++Dfk TVlBWsR5QGkluRA9sK3n8lmHlEp6hsiN/g8obnduoQv5Sp6y3SmK1n5SMPepZn00xVXQbuUt1pns FwEiRQv+PVjjwa+Z5RFCOMRcWiPRKbIVb0W0ikJ1srcoLgZa+s1GS7xhMhvPmSQA4fQ+eiFbpuo6 VH67fHp7qAROCtXTgfBgDTZp6UBFlSZBH2kPB2JWhafLzxyJhX8OhyqWjskyRrEPh8O1htu2mcLA rHVUMx1iLR3hcW4Z00qpRzQGWLi35T7+KkoEvLoCMfbDORTe0uQ3vM+SnZK53AyMyZKKAhcbbM3h Nd6sOjjlHHASJNUmoOHSoqgqxfHmWZN1nQlrL7Mu6rYbX5J8ZbfRYuAPlIkDf483gwMtaROpdi0J UH6JEWw3pNGdarqiBRxfQCBb4q61W X-Report-Abuse-To: spam@s01.spamexperts.axc.nl X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 185.182.56.112 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.lisp.guile.user:14573 Archived-At: Hi Guilers, I want to run an external process, and capture both its stdout and stderr output streams. I didn't find an easy way to get a port for an external process' stderr, other than wrapping the call to the process in "with-error-to-port". My questions are: 0) Did I miss something obvious? :) 1) why doesn't the second approach in the code below work (the output-string is always empty)? 2) are there any other (better) solutions? 3) I suppose my approach with (pipe) might block if the process writes too much data to stderr before I read from the pipe. Should I use "select" to interleave reads from stdout and stderr? thank you! Thomas (use-modules (ice-9 format) (ice-9 popen) (ice-9 textual-ports)) (define (run-command) (let ((process (open-input-pipe "./stdoutstderr.sh"))) (format #t "stdout: '~a'~%" (get-string-all process)) (close-pipe process))) ;; Works: (let ((err-pipe (pipe))) (with-error-to-port (cdr err-pipe) run-command) (close-port (cdr err-pipe)) (format #t "stderr: '~a' ~%" (get-string-all (car err-pipe)))) ;; Doesn't work: (get-output-string) returns empty string. (let ((err-port (open-output-string))) (with-error-to-port err-port run-command) (format #t "stderr: '~a'~%" (get-output-string err-port)) (close-output-port err-port))