stdout problems in RealBasic
stdout problems in RealBasic
2007
There is a really annoying, well annoying to me, bug in REALbasic console applications. It turns out that it isn’t really a bug so much as an oversight. The console applications use only CStrings as parameters to the write functions to stdout. Since CStrings are null terminated, the writing stops if you’re trying to output binary data that happens to contain any nulls. So while you can pipe text, you cannot pipe binary data of any kind into or out of an RB app due to this limitation.
Today I decided that the workaround was to declare down to the lower level system “write” command that can output from memory directly and cares not what the data actually contains. Some messing around revealed that I could not declare to LibC but rather to the MacOSX wrapper for it which is “System.Framework” and then it works!
The declare looks like this:
Sending nulls to stdout in RB
10/3/07
A workaround for sending binary data containing nulls to stdout in a console app built with REALbasic.
Watch that word wrap there.
and to write the contents of a memory block to stdout you call it like this:
Potential problems with this are that I’m assuming that the file handle for stdout will always be 1. There might be a way to get this via some other call, but so far it looks like this is not too dangerous of an assumption. And of course it’s up to you to check the return code and see that it wrote anything. In my quick testing here this gets me around the binary data limitation!
James