<nobu.nokada / softhome.net> wrote in message news:200306130007.h5D07jTS022980 / sharui.nakada.kanuma.tochigi.jp... > Hi, > > At Fri, 13 Jun 2003 08:05:39 +0900, > Sean O'Dell wrote: > > Now the problem I'm having is that print statements are causing the program > > to hang. Presumably because the stdio handles Ruby is using aren't opened > > properly because Ruby is being embedded into a true (non-console) Windows > > application. I tried using AllocConsole() and freopen() to open up the > > handles, and that does allow *my* application to print just fine, but any > > Ruby script code that tries to print simply hangs my application. > > You might need to use SetStdHandle() instead of freopen(). I found the trick to getting the Ruby API to print from a Borland Builder true Windows application, I think. Basically, "late-load" the bcc32 Ruby ..dll so it doesn't load until the first Ruby API function is called. Builder has this option, but I'm not sure about MSVC++. The trick is two-fold. One, call AllocConsole() any time *before* your first Ruby call so the Ruby .dll will automatically load *after* AllocConsole() is called. Then simply make the calls shown below before calling any Ruby API function that might try and print to the console: dup2(open("con", O_RDONLY), 0); dup2(open("con", O_WRONLY), 1); dup2(open("con", O_WRONLY), 2); Pretty simple. It also appears from some simple testing I just did, that you can skip the AllocConsole() call if you open files other than "con" and redirect Ruby's output to a file, or perhaps a pipe or socket or what-not. Sean O'Dell