From: ····@att.net
Subject: Re: a small SBCL question
Date: 
Message-ID: <1167440044.244636.136180@s34g2000cwa.googlegroups.com>
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?

Many thanks!

Cheers,
David

From: ······@gmail.com
Subject: Re: a small SBCL question
Date: 
Message-ID: <1167440428.068145.153620@s34g2000cwa.googlegroups.com>
····@att.net wrote:
> 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?

Because on UNIX traditionally wildcards are expanded by your shell, not
by, say, /bin/ls -- unlike MS-DOS, BTW. :) There are exceptions, of
course (scp knows about them, find...), but not ls.

You can try using "/bin/sh" for the command, (list "/bin/ls"
"/tmp/*.lisp") for its arguments.

> Many thanks!

Welcome!

> Cheers,
> David

Paul B.
From: Zach Beane
Subject: Re: a small SBCL question
Date: 
Message-ID: <m3r6ui5h56.fsf@unnamed.xach.com>
····@att.net 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
From: Zach Beane
Subject: Re: a small SBCL question
Date: 
Message-ID: <m3mz565g3u.fsf@unnamed.xach.com>
Zach Beane <····@xach.com> writes:

> 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"))

Oops, this should be:

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

Zach
From: Pascal Bourguignon
Subject: Re: a small SBCL question
Date: 
Message-ID: <87vejunqr0.fsf@thalassa.informatimago.com>
····@att.net 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?

Yes.  Anybody with the most basic understanding of unix shells.

In:

  ls *.lisp

it's the shell that expands the wildcard, not the /bin/ls command.


If you want to implement a similar feature in lisp, you'd have to use
DIRECTORY:

   (sb-ext:run-program "/bin/ls" (cons "-l" (directory "/tmp/*.lisp"))
                       :output :stream)


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein