[squeak-dev] [OSProcess] How to read the stdout of a process running an infinite loop?

David T. Lewis lewis at mail.msen.com
Tue May 20 19:14:36 UTC 2008


On Tue, May 20, 2008 at 05:10:45PM +0200, Noury Bouraqadi wrote:
> Hi,
> 
> Gautier and I have a software written in C that loops infinitly doing  
> some computations. At every iteration it displays something on the  
> shell. We want to read the output into squeak. We can not wait for the  
> end of the computations, since it's an infinite loop :-)
> 
> Any hints?

I don't have Squeak system to look at right now, but the way to do
this is to use a PipeableOSProcess and register an interest in data
available. Load CommandShell in addition to OSProcess to get the
necessary classes.

One of the SUnit test suites in the CommandShell shows how the
#changed:/#update: notifications are set up for a CommandShell window.
For your application, I think you can just add a dependent to your
instance of PipeableOSProcess to get the data available notification
(but I don't remember the details of how I set this up).

Class ProxyPipeline is a good way to start your C program, see the
class side examples. This can be used to create a PipeableOSProcess
that runs your C program, and you can get #changed: notifications
whenever data becomes available on the pipe from the C program. Use
PipeableOSProcess>>upToEnd to read the data (note, there is also an
#upToEndOfFile method that reads all data until your C program
terminates - that is not what you want).

It is best if your VM has AioPlugin in addition to OSProcessPlugin,
but it will work even without this (a polling loop will be used
instead of real aio events).

Dave




More information about the Squeak-dev mailing list