In ACL on Linux, I use run-shell-command to start a process that generates output to stdout. I can read from the stream that run-shell-command returns with read-char but I need to be reading bytes, not characters. When I try to use read-byte it says
Error: No methods applicable for generic function #<STANDARD-GENERIC-FUNCTION STREAM-READ-BYTE> with args (#<BIDIRECTIONAL-TERMINAL-STREAM fd 16/15 @ #x20256dca>) of classes (BIDIRECTIONAL-TERMINAL-STREAM)
Richard James Panturis Giuly <n...@spam.com> writes:
> In ACL on Linux, I use run-shell-command to start a process that > generates output to stdout. I can read from the stream that > run-shell-command returns with read-char but I need to be reading > bytes, not characters. When I try to use read-byte it says
> Error: No methods applicable for generic function > #<STANDARD-GENERIC-FUNCTION STREAM-READ-BYTE> with args > (#<BIDIRECTIONAL-TERMINAL-STREAM fd 16/15 @ #x20256dca>) > of classes > (BIDIRECTIONAL-TERMINAL-STREAM)
> how can I read bytes instead efficiently?
On Unix, character streams and byte streams are fairly interchangeable. Have you measured READ-CHAR is actually slower than READ-BYTE?
If this is really the case, you could try doing a CHANGE-CLASS on your stream to BIDIRECTIONAL-BINARY-SOCKET-STREAM. Alternatively, you can create your own binary stream and give that as argument to the :output key argument of RUN-SHELL-COMMAND.
-- Lieven Marchand <m...@bewoner.dma.be> Lambda calculus - Call us a mad club
* Richard James Panturis Giuly <n...@spam.com> | how can I read bytes instead efficiently?
Which inefficient solutions have you tried so far? (Since you use one of those extremely annoying invalid return addresses, I'm not inclined to provide you with the solution I used ere the dawn of bivalent¹ streams in Allegro CL.)
#:Erik ------- ¹ "multivalent" in recent terminology change, but it sounds silly -- If this is not what you expected, please alter your expectations.
When I convert the input stream to an INPUT-BINARY-SOCKET-STREAM, the read-byte function works but still gives characters. I need integers (or numbers of some kind) rather than characters.
I don't know how to create a binary stream, could you fill me in? (All I found were functions to make streams from existing streams.)
If you know how I can convert a character to an integer that would be fine too, I just thought converting every byte might be inefficient.
> On Unix, character streams and byte streams are fairly > interchangeable. Have you measured READ-CHAR is actually slower than > READ-BYTE? > If this is really the case, you could try doing a CHANGE-CLASS on your > stream to BIDIRECTIONAL-BINARY-SOCKET-STREAM. Alternatively, you can > create your own binary stream and give that as argument to the :output > key argument of RUN-SHELL-COMMAND.
* Richard James Panturis Giuly <n...@spam.com> | If you know how I can convert a character to an integer that would | be fine too, I just thought converting every byte might be | inefficient.
The function char-code returns the integer code of the character. It's essential a type-changing function, as both characters and integers are immediate values, and at least in Allegro CL is a simple bit-shift operation if you declare the character's type.
#:Erik -- If this is not what you expected, please alter your expectations.