From: Mounir Idrassi Date: 2006-11-19T23:39:06+09:00 Subject: io_write (io.c) bug (and its fix) under MS Windows for GUI apps (rubyw) Hi all, I recently encountered a problem under MS Windows where a GUI application that runs correctly with ruby.exe refused to start with rubuw.exe (1.8.5 version). After some digging I found that the problem came from the function io_write in io.c : rb_sys_fail was called after receiving -1 from io_fwrite. Actually, the ruby interpreter wanted to print some warning to "rb_stderr" and because its a GUI application with no console attached to it the C runtime returned -1. If I use ruby.exe instead, the warnings are printed correctly. To correct this behavior, it's sufficient to test if we have a console attached to the current process and in case no one is found, we don't call rb_sys_fail if the target stream is either rb_stderr ou rb_stdout. I made the following modifications to implement this : - Add a function named "ProcessHasConsole" in case we are compiling for MS Windows that returns TRUE if a console is attached to the current process and FALSE otherwise. You can find its body at the end of this email. - In "io_write" body, replace the statement "if (n == -1) rb_sys_fail(fptr->path);" with the following : if (n == -1) { #ifdef _WIN32 if( (io != rb_stderr && io != rb_stdout) || ProcessHasConsole()) #endif rb_sys_fail(fptr->path); } I hope this can help Windows users of ruby that were affected by the same problem as me. Is there any specific protocol for submitting patches? Cheers, Mounir IDRASSI IDRIX web: http://www.idrix.fr PS: body of the function "ProcessHasConsole" : #ifdef _WIN32 static BOOL ProcessHasConsole() { TCHAR szTitle[128]; if(GetConsoleTitle(szTitle,128) || GetLastError() == ERROR_SUCCESS) return TRUE; else return FALSE; } #endif