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

David T. Lewis lewis at mail.msen.com
Fri May 15 11:29:47 UTC 2009


On Fri, May 15, 2009 at 01:31:57AM -0400, Jason Rogers wrote:
> On Tue, May 12, 2009 at 8:59 PM, David T. Lewis <lewis at mail.msen.com> wrote:
> >
> > ExternalCommandShell does this all in an event-driven manner with
> > no polling, so you can copy that if you want to get fancy. Otherwise
> > a simple polling loop in your process will probably work well enough.
> > Put a 100 ms delay in whatever loop is reading from stdIn an you will
> > get tolerable performance.
> >
> > Dave
> 
> Thanks again Dave for the help.  My tack was to "copy"
> ExternalCommandShell's pattern.  StdIn is working fine, but when I
> write to StdOut nothing seems to actually "get out".  Any ideas?

Try doing a #flush after you write to stdOut, like this:

  OSProcess thisOSProcess stdOut
     nextPutAll: 'hello world';
     nextPut: Character lf;
     flush.

On unix (OS X), the I/O is done through the C stdio library. There is
normally some buffering going on at that level, so if you flush the
stream it should push the bytes out the tube.

> I'm running on Mac, I don't have the AioPlugin installed (I've
> commented out the inform: that tells about the plugin not being there
> and therefore polling will be used).  I'm not verbose enough at
> building plugins.

Don't worry about it.  AioPlugin is used by CommandShell to do the
event-driven I/O. If the plugin is not present, it gives you a warning
and falls back on polling loops instead of using the "data ready"
events from AioPlugin. For your application, polling loops should
be good enough.

Dave




More information about the Squeak-dev mailing list