From: Nobuyoshi Nakada Date: 2006-12-01T02:14:42+09:00 Subject: Re: io_write (io.c) bug (and its fix) under MS Windows for GUI apps (rubyw) Hi, At Sun, 19 Nov 2006 23:39:06 +0900, Mounir Idrassi wrote in [ruby-core:09572]: > - In "io_write" body, replace the statement "if (n == -1) > rb_sys_fail(fptr->path);" with the following : It doesn't feel appropriate to modify io.c. You may want to redirect stdios to the null device, I guess. Index: win32/win32.c =================================================================== RCS file: /cvs/ruby/src/ruby/win32/win32.c,v retrieving revision 1.197 diff -p -U 2 -r1.197 win32.c --- win32/win32.c 30 Oct 2006 14:23:03 -0000 1.197 +++ win32/win32.c 30 Nov 2006 16:05:09 -0000 @@ -1732,13 +1732,23 @@ static void init_stdhandle(void) { + int nullfd = -1; + int keep = 0; +#define open_null(fd) ( \ + ((nullfd < 0) ? \ + (nullfd = open("NUL", O_RDWR|O_BINARY)) : 0), \ + ((nullfd == fd) ? \ + (keep = 1, fd) : \ + dup2(nullfd, fd))) + if (fileno(stdin) < 0) { - stdin->_file = 0; + stdin->_file = open_null(0); } if (fileno(stdout) < 0) { - stdout->_file = 1; + stdout->_file = open_null(1); } if (fileno(stderr) < 0) { - stderr->_file = 2; + stderr->_file = open_null(2); } + if (nullfd >= 0 && !keep) close(nullfd); } #else -- Nobu Nakada