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? Thanks, Noury ------------------------------------------------------------------ Dr. Noury Bouraqadi - Enseignant/Chercheur Responsable de l'enseignement de l'informatique ARMINES - Ecole des Mines de Douai - Dept. I.A. http://vst.ensm-douai.fr/noury European Smalltalk Users Group Board http://www.esug.org ------------------------------------------------------------------ |
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 |
In reply to this post by Noury Bouraqadi
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? Try the attached change set for an example. I made a shell script that generates output, named it "test.sh", and ran it from Squeak as follows. | proxyWatcher | proxyWatcher := ReadFromExternalProgram programName: 'test.sh'. proxyWatcher start. (Delay forSeconds: 10) wait. proxyWatcher stop. The proxyWatcher runs the external program for 10 seconds, copying its output to the Transcript as new data becomes available. Hope this helps, Dave ReadFromExternalProgram-dtl.2.cs.gz (1K) Download Attachment |
Thanks David. We'll give it a try.
Noury On 21 mai 08, at 04:48, David T. Lewis wrote: > 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? > > Try the attached change set for an example. I made a shell script that > generates output, named it "test.sh", and ran it from Squeak as > follows. > > | proxyWatcher | > proxyWatcher := ReadFromExternalProgram programName: 'test.sh'. > proxyWatcher start. > (Delay forSeconds: 10) wait. > proxyWatcher stop. > > The proxyWatcher runs the external program for 10 seconds, copying its > output to the Transcript as new data becomes available. > > Hope this helps, > Dave > > <ReadFromExternalProgram-dtl.2.cs.gz> Noury Bouraqadi ------------------------------------------------------------------ Dr. Noury Bouraqadi - Enseignant/Chercheur Responsable de l'enseignement de l'informatique ARMINES - Ecole des Mines de Douai - Dept. I.A. http://vst.ensm-douai.fr/noury European Smalltalk Users Group Board http://www.esug.org ------------------------------------------------------------------ |
Free forum by Nabble | Edit this page |