Re: a small SBCL question



dneu@xxxxxxx writes:

Pascal Bourguignon wrote:

S/CL-USER[39]> (with-open-stream (files
(sb-ext:process-output
(sb-ext:run-program "/bin/ls" '("-l" "/tmp/a.lisp")
:output :stream)))
(loop :for line = (read-line files nil nil)
:while line :do (princ line) (terpri)))
-rw-r--r-- 1 pjb pjb 93 2006-12-13 21:21 /tmp/a.lisp
NIL


I tried the example above, with a wildcard, i.e. "/tmp/*.lisp" instead
of "/tmp/a.lisp",
and no files were found, and there are files matching the pattern.

Could someone explain why?

Wildcard expansion is done by the shell, not by programs like "ls"
(most of the time, anyway). RUN-PROGRAM uses something like exec(2) to
run programs. If you wanted shell-style wildcard expansion, you'd have
to run a shell:

(sb-ext:run-program "/bin/sh" (list "-c" "/tmp/*.lisp"))

At that point, the argument after "-c" should consist of *all* your
arguments serialized to a string, for the shell to deserialize into
separate arguments. This is error-prone due to quoting and shell
metacharacters and the like. Normal SBCL RUN-PROGRAM doesn't have any
of that trouble since it uses exec directly.

Zach
.



Relevant Pages

  • Re: Ada.Command_Line and wildcards
    ... wildcard expansion the shell does, ... This is exactly the same reason that anonymous access types are not a usable ... Using them requires the client ...
    (comp.lang.ada)
  • Re: Ada.Command_Line and wildcards
    ... So could you please explain why you think the Unix behaviour is ... wildcard expansion the shell does, ... That depends on the shell the user is using. ... special sub-language to specify file sets it's not the program's nor ...
    (comp.lang.ada)
  • Re: exec command
    ... glob does what you use ls for without a slow exec and portable. ... wildcard expansion and exec isn't called in a shell. ...
    (comp.lang.tcl)
  • Re: my PC or Linux?
    ... The shell handles wildcard expansion. ... it isn't a Bash oddity. ... It's how quoting has always worked. ...
    (alt.os.linux)
  • Re: exec issues with globbing
    ... In unix anyway it is the shell that expands wildcards when you ... exec scp you are not invoking a shell. ... the list of files matching the glob as a string. ...
    (comp.lang.tcl)