guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the output port of `system*'?


From: Taylan Ulrich Bayirli/Kammer
Subject: Re: What is the output port of `system*'?
Date: Sun, 27 Apr 2014 00:37:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

"Diogo F. S. Ramos" <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]