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


_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to