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

Sean P. DeNigris sean at clipperadams.com
Tue May 26 13:44:53 UTC 2020


Sorry, I just saw this thread. For the future, I did a small wrapper like
this that might help [1]. It looks like I didn't convert the repo to Tonel
yet and IIRC there are few dependencies other than OSP, so it may load in
Squeak (or could be used for inspiration). I would also be happy to accept
PRs to make it so. I probably will convert to Tonel at some point - although
it looks like Tonel support in Squeak may be imminent, so hopefully no
problem there :)


Martin Kuball wrote
> Mybe it is possible to reuse more of your high-level code.

This is what I ended up with [2]:
	| p result |
	p := PipeableOSProcess waitForCommand: commandString.
	p succeeded ifFalse: [ ^ self error: 'tesseract failed with: ', p
errorUpToEnd ].
	result := self tempFile readStreamDo: [ :str | str contents ].
	self tempFile delete.
	^ result.

If I had to do it again, I'd probably try via FFI. I've had a longstanding
belief that wrapping command line stuff is an easy way to "get it to work"
and then I can later "get it right" with FFI, but after doing a lot of this
sort of thing, there are so many quirks that I think it might usually be
easier to just start with FFI (although maybe the grass is always
greener...).

[1]. https://github.com/seandenigris/Tesseract-St
[2].
https://github.com/seandenigris/Tesseract-St/blob/master/src/Tesseract.package/Tesseract.class/instance/evaluate..st



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html


More information about the Squeak-dev mailing list