Re: sys:open-pipe oddities...
Well, the base-string answer got me to a point where I
can get the external excutable running. Now I'm facing
a slightly more challenging problem, which might be more
of an OS I/O issue, but I'm not sure.
The program to which I'm opening a pipe accepts a
filename as an argument, and it reads its input from this
file. As I'm opening a pipe, I'm going to be writing that
input directly. (I may run into the inability to close just
one side of a pipe, an issue I've had in the past, but
I'll attack that problem when I come to it.) When I'm
working on a command prompt, it's no problem to
give /dev/stdin as the file argument, or even /dev/fd/0.
However, if I built my command line, or my list of
command strings, with such an argument, I get a
FILE NOT FOUND error.
Here's an example with cat:
-----------------------------------
;; here's an example with 'cat -' where an '-' tells cat to
;; read from standard input
AS 84 > (setf pipe (sys:open-pipe (list (coerce "/bin/cat"
'base-string) (coerce "-" 'base-string)) :direction :io))
#<System::Pty-Stream "/bin/cat">
AS 85 > (write-line "line 1" pipe)
"line 1"
AS 86 > (write-line "line 2" pipe)
"line 2"
AS 87 > (force-output pipe)
Nil
AS 88 > (read-line pipe)
"line 1"
Nil
AS 89 > (read-line pipe)
"line 2"
Nil
;; here's 'cat /dev/stdin' which fails with
;; cat: /dev/stdin: Permission denied
AS 92 > (setf pipe (sys:open-pipe (list (coerce "/bin/cat"
'base-string) (coerce "/dev/stdin" 'base-string)) :direction :io))
#<System::Pty-Stream "/bin/cat">
AS 93 > (write-line "line 1" pipe)
"line 1"
AS 94 > (write-line "line 2" pipe)
"line 2"
AS 95 > (force-output pipe)
Error: Error while writing on stream #<System::Pty-Stream "/bin/cat">:
Broken pipe [Unix Errno = 32].
1 (continue) Try writing to #<Editor::Rubber-Stream #<Editor:Buffer
CAPI interactive-pane 2> 11AE4B7F> again.
2 (abort) Return to level 0.
3 Return to top loop level 0.
Type :b for backtrace, :c <option number> to proceed, or :? for other options
AS 96 : 1 > :a
AS 97 > (read-line pipe)
"cat: /dev/stdin: Permission denied"
Nil
AS 98 > (read-line pipe)
Error: End of file while reading stream #<System::Pty-Stream "/bin/cat">.
1 (abort) Return to level 0.
2 Return to top loop level 0.
Type :b for backtrace, :c <option number> to proceed, or :? for other options
AS 99 : 1 >
-------------------------------------
I suspect that this might not be a LispWorks issue so
much as a 'I'm naive about pipes' issue, so do let me know
if that's the case.
Thanks!
On 6/9/06, Taylor, Joshua <tayloj@rpi.edu> wrote:
> Ah, great, tihs is easy to work around then.
>
> By the way, is there somewhere on the Lispworks
> website where one can search for outstanding bugs?
> I found the area to report them, and the place to download
> patches, but I'm always worried when I bring up something
> that seems to be a bug that i've not searched some existing
> store of known bugs. Is there such a searchable store?
> (Aside from the list archives?)
>
> On 6/9/06, Martin Simmons <martin@lispworks.com> wrote:
> >
> > >>>>> On Fri, 9 Jun 2006 11:23:16 -0400, "Taylor, Joshua" <tayloj@rpi.edu> said:
> > >
> > > Hello all,
> > > I'm playing with pipe streams again, and I'm having a bit
> > > of an issue with command line arguments. I'm on
> > > Mac OS X 10.4.6, on Lispworks 4.4.6 Professional.
> > >
> > > Quoth the docs:
> > >
> > > "Signature
> > > open-pipe command &key direction element-type interrupt-off shell-type => stream
> > > ...
> > > If command is a string then it is passed to the shell as the command
> > > to run. If command is a list, then the first element is the command to
> > > run directly and the other elements are passed as arguments on the
> > > command line. If command is nil , then the shell is run."
> > >
> > > So, something like
> > >
> > > (setq qq (sys:open-pipe "/bin/ls -l"))
> > > (loop while (print (read-line qq nil nil)))
> > >
> > > works, as I'd expect it to, the shell interprets the -l correctly.
> > > This example works if I just give "ls -l" as well, which also
> > > seems good; the shell is making sure PATH is consulted.
> > >
> > > Evaluating
> > > (setq qq (sys:open-pipe (list "/bin/ls")))
> > > in the listener causes a terminal window to come up,
> >
> > This is caused by a bug in sys:open-pipe when the arguments are not
> > base-strings. It works in some situations because the Lisp reader creates
> > strings with the same element type as the stream being read.
> >
> > To work around this, you can do
> >
> > (setq qq (sys:open-pipe (list (coerce "/bin/ls" 'base-string))))
> >
> > --
> > Martin Simmons
> > LispWorks Ltd
> > http://www.lispworks.com/
> >
> >
>
>
> --
> =====================
> Joshua Taylor
> tayloj@rpi.edu
>
--
=====================
Joshua Taylor
tayloj@rpi.edu