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

Martin Kuball martinkuball at web.de
Fri May 15 19:20:17 UTC 2020


Am Donnerstag, 14. Mai 2020, 23:27:59 CEST schrieb David T. Lewis:
> 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

Hi Dave,

thanks for your answer. Acutally I did install CommandShell because I thougth
it might help me understand the usage of OSProcess. And maybe it will if I
give it more time.

So here is what I did: I configure the following repository:

MCHttpRepository
	location: 'http://www.squeaksource.com/OSProcess'
	user: ''
	password: ''

and installed OSProcess-Base dtl.71, OSProcess-AIO dlt.9 and OSProcess-Unix
dtl.35. But I do not see any mention of a head label. So where did I go wrong?

The command you suggested worked. At least if I provide the image to tesseract
as a file. I will go on with the debugger and try to find out how to feed the
image data to stdIn.

Martin





More information about the Squeak-dev mailing list