From: Taylan Ulrich Bayirli/Kammer <taylanbayirli@gmail.com>
To: "Diogo F. S. Ramos" <dfsr@riseup.net>
Cc: guile-user@gnu.org
Subject: Re: What is the output port of `system*'?
Date: Sun, 27 Apr 2014 00:37:20 +0200 [thread overview]
Message-ID: <87siozn2e7.fsf@taylan.uni.cx> (raw)
In-Reply-To: <87mwf7hnly.fsf@nebulosa.milkyway> (Diogo F. S. Ramos's message of "Sat, 26 Apr 2014 16:55:37 -0300")
"Diogo F. S. Ramos" <dfsr@riseup.net> writes:
> The following program doesn't output to a string, which I expected.
>
> (define foo
> (with-output-to-string
> (lambda ()
> (system* "ls" "/tmp"))))
As the manual says about `system*':
> The command is executed using fork and execlp.
That implies certain restrictions. See (ice-9 popen), documented in
(info "(guile) Pipes"). That also spawns a process but sets its stdout
to a Unix pipe for which it gives you a Guile port, from which you can
drain the output to construct a string.
(Details: `with-output-to-string' could be said to work by setting the
current output port to some special value (a "string port" I guess) that
tells the deepest Guile IO procedures to construct a string instead of
writing to a file descriptor; when you spawn a separate process you
obviously lose this ability, the spawned process simply inherits the
current stdout file descriptor of the Guile process and writes to that.)
By the way, you might be better off doing things directly within Guile
instead of spawning external processes and trying to use their output.
In case you really wanted to do something with the output of ls(1), you
might want to use (ice-9 ftw) instead, but I suppose it was just an
example.
Taylan
next prev parent reply other threads:[~2014-04-26 22:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-26 19:55 What is the output port of `system*'? Diogo F. S. Ramos
2014-04-26 22:37 ` Taylan Ulrich Bayirli/Kammer [this message]
2014-04-27 5:30 ` Diogo F. S. Ramos
2014-04-27 6:09 ` Mark H Weaver
2014-04-27 19:27 ` Diogo F. S. Ramos
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=87siozn2e7.fsf@taylan.uni.cx \
--to=taylanbayirli@gmail.com \
--cc=dfsr@riseup.net \
--cc=guile-user@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).