[squeak-dev] How to use OSProcess with stdin and stdout

David T. Lewis lewis at mail.msen.com
Thu May 14 21:27:59 UTC 2020


On Thu, May 14, 2020 at 09:37:26PM +0200, Martin Kuball wrote:
> Hi!
> 
> I'm trying to do some OCR from squeak using tesseract. I installed OSProcess.
> So far so good. But I don't know what classes to use for stdIn and stdOut. My
> code would look something like this:
> 
> | proc stdIn stdOut d |
> stdIn := ???
> stdOut := ???
> proc := ExternalUnixOSProcess forkAndExec: '/usr/bin/tesseract' arguments:
> #('-' '-' '--dpi' '100') environment: nil descriptors: (Array with: stdIn
> with: stdOut with: nil).
> proc ifNil: [self class noAccessorAvailable].
> d := Delay forMilliseconds: 50.
> [proc runState == #complete] whileFalse: [d wait].
> " and now read the text from stdOut..."
> 
> Can someone fill in the blanks or point me to code that does similar things?
> Thanks very much.

Hi Martin,

First, please also install CommandShell in addition to OSProcess. Get the
latest versions of both OSProcess and CommandShell, regardless of the version
of Squeak you are using. If you are using SqueakMap to load them, then please
select the versions labelled "(head)".

Start out by trying something like this:

    OSProcess outputOf: 'tesseract - - --dpi 100'

I'm not sure if this will do what you want but please give it a try,
and if it does not work I'll try to give a better answer.

This uses a couple of new methods that I added to OSPrecess recently,
but have not mentioned until now. If it proves to be useful you, you
will be the first :-)

Assuming that it works, here is what will have happened:

- The argument string is parsed into a unix-style command pipeline

- The pipeline is all objects, with OS process proxies doing the work

- When evaluated, and stderr result will show up in an error notifier
  in your image (proceed though the notifier)

- Command stdout is collected and answered as the result of #outputOf:

I would recommend running this in a debugger so you can step through
it and see what is going on.

Dave

> 
> 
> 


More information about the Squeak-dev mailing list