[squeak-dev] reading and writing from STDIN and STDOUT

David T. Lewis lewis at mail.msen.com
Fri May 15 21:10:45 UTC 2009


On Fri, May 15, 2009 at 11:29:15AM -0300, Casimiro de Almeida Barreto wrote:
>
>  I'm experiencing a similar problem: I have a method that calls an external function
>  via FFI. This function reports its progress via stdout. I'd like such output could be
>  redirected either to Transcript or to a squeak shell (worse). But that's not
>  happening. The routine prints on the shell where squeak was started. When squeak is
>  started in the form of something like: nohup squeak > /dev/null 2> /dev/null & the
>  routine redirects to the "device" (meaning /dev/tty...).
>  One consequence is that how there's no IO perceived by squeak, everything freezes
>  until routine is done (about 12 hours).
>  What would be the best way of redirecting stdio (file descriptor) to Transcript?

Do you mean that the external library is writing to stdout, and you
want to be able to see that output from within the Squeak image? In
that case you want Squeak to be reading its own standard output, and
redirecting it to the Transcript?

There is probably some way to do that, although I can't think of anything
right now. If you don't need to be too fancy about it, consider just
directing stdout to a file and periodically reading the file contents
from Squeak.

Or direct stdout to a named pipe (unix mkfifo command) and read from
the named pipe. If you use a named pipe, you will need to open it as
a file stream in Squeak, then set the file stream to non-blocking mode
before you use it, otherwise you will lock up your Squeak VM. Search
for methods with 'setnonblocking' in the name. It's somewhere in
OSProcess, but I don't have Squeak with me to check right now.

Dave




More information about the Squeak-dev mailing list