On Jan 10, 2008 10:11 AM, Ozzi <[EMAIL PROTECTED]> wrote:

> I am using the following code, which just takes a single string:
> (define (system->string cmd)
>    (string-chomp (with-input-from-pipe cmd read-all)))

First, the string-chomp is pointless unless you're reading only one
line.  Why chomp just the last newline of a multi-line string?
Assuming you did want to read one line of output, your code becomes

(with-input-from-pipe cmd read-line)

since read-line does a chomp internally.  Not really worthy of a
utility function.

If you are reading multi-line output, and you want to slurp everything
into one string, you don't need the chomp so you'll get:

(with-input-from-pipe cmd read-all)

Anyway, slurping everything is pretty rare.  Most of the time you
parse the output line-by-line without allocating a large buffer, which
system->string can't handle.

Finally, if you really do want to slurp all lines at once, you might
as well use read-lines to slurp them into a list of strings (without
trailing newlines):

#;3> (with-input-from-pipe "ls" read-lines)
("Applications" "Desktop" "Documents" ...)


_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to