[Top][All Lists]
[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" ...)
- Re: [Chicken-users] Adding (system->string) somewhere, (continued)
- Re: [Chicken-users] Adding (system->string) somewhere, Ivan Raikov, 2008/01/10
- Re: [Chicken-users] Adding (system->string) somewhere, Ozzi, 2008/01/14
- Re: [Chicken-users] Adding (system->string) somewhere, Kon Lovett, 2008/01/14
- Re: [Chicken-users] Adding (system->string) somewhere, Zbigniew, 2008/01/14
- Re: [Chicken-users] Adding (system->string) somewhere, Elf, 2008/01/14
- Re: [Chicken-users] Adding (system->string) somewhere, Tobia, 2008/01/15
- Re: [Chicken-users] Adding (system->string) somewhere, Zbigniew, 2008/01/15
- Re: [Chicken-users] Adding (system->string) somewhere, Kon Lovett, 2008/01/15
- Re: [Chicken-users] Adding (system->string) somewhere, Zbigniew, 2008/01/15
- Re: [Chicken-users] Adding (system->string) somewhere, Kon Lovett, 2008/01/15
Re: [Chicken-users] Adding (system->string) somewhere,
Zbigniew <=