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

David T. Lewis lewis at mail.msen.com
Sun May 17 02:08:17 UTC 2009


On Sat, May 16, 2009 at 10:08:46PM -0300, Casimiro de Almeida Barreto wrote:
> 
> David T. Lewis escreveu:
> 
>> 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?
>> 
>> (...)
> 
>    Yes, I have something like (the most time consuming routine):
>        fInterface apiFannTrain: theFANN
>            onFile: trainingDataFileName
>            times: theMaxEpochs
>            reporting: numberOfEpochs
>            toPrecision: theDesiredError.
>    Where apiFannTrain is:
>    apiFannTrain: aFann onData: aTrainData times: aNumber1 reporting: aNumber2 toPrecision: aFloat
>        < cdecl: void 'fann_train_on_data' ( Fann* FannTrainData* ulong ulong float ) module: 'floatfann' >
>        ^ self externalCallFailed.
>    And that routine outputs progress to stdout. Problems are:
>     1. As I cannot redirect stdout from inside squeak, I'm not able to watch progress inside squeak (Transcript, morph... you name it)
>     2. As this kind of output doesn't create context change within squeak VM, apiFannTrain freezes VM until its completion (which may
>        take more than 12 hours). Geez, it's a long time with frozen squeak...
> 
>    I just figured out that if it was possible to redirect stdout to something inside squeak it would allow me to fix the two problems.
> 
> By the way, as the apiFannTrain is not preemptive from inside squeak,
> there's no use in "fork" it.

Actually, I think that you *do* want to fork it. If the procedure that you
are calling from FFI will run for a long time, then you would probably
want to have it run in a separate process or thread such that it would
not block the Squeak VM in the FFI call.

This is an interesting problem. I do not have an answer for you now,
but there must be a way to do it. I will reply back later if I think
of a solution.

(By the way, it is hard for me to read your posting because it is in
an html format. If you can change your mail to send plain text to the
squeak-dev list, that would be helpful.)

Dave




More information about the Squeak-dev mailing list