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: Tobia
Subject: Re: [Chicken-users] Adding (system->string) somewhere
Date: Tue, 15 Jan 2008 13:26:23 +0100

Elf wrote:
how about

(define (system->string . args)
(string-chomp (with-input-from-pipe (string-join args " ") read- all)))

IMHO, if this system->string is going to be of any use, it should quote its arguments against any possible interpretation by the shell. Fortunately there is a simple way which supposedly works with every flavour of UNIX shell: replace every ' with '\'' and enclose each argument in '...'

(define (system+ . args)
  (define (shell-quote arg)
    (conc "'"
          (string-substitute "'" "'\\''" arg)
          "'"))
  (with-input-from-pipe (string-join (map shell-quote args)
                                     " ")
                        read-lines))

#;8> (system+ "ls" "/Applications/iWork '08")
("Keynote.app" "Numbers.app" "Pages.app")

The read-lines and read-all versions are both useful, as are custom loops that parse the output line-by-line or character-by-character, so maybe we should make a sort of with-input-from-system that only does the quoting?


Tobia




reply via email to

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