chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Adding (system->string) somewhere


From: Zbigniew
Subject: Re: [Chicken-users] Adding (system->string) somewhere
Date: Mon, 14 Jan 2008 14:10:35 -0600

On Jan 10, 2008 10:11 AM, Ozzi <address@hidden> 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" ...)




reply via email to

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