X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Mon, 23 May 2011 17:39:44 +0200 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: CYGWIN=tty round 2 Message-ID: <20110523153944.GM3051@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <20110522211906 DOT GA13428 AT ednor DOT casa DOT cgf DOT cx> <1306119201 DOT 4572 DOT 4 DOT camel AT YAAKOV04> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On May 23 12:49, Andy Koppe wrote: > The reason is that XWin.exe is built with -Wl,--subsystem,windows (or > -mwindows, which implies it), which allows it to be invoked directly > from a shortcut or the Run.. dialog without popping up a console or > requiring a console hiding hack. (It's the same for mintty.) > > The downside is that Windows also won't hook it up to the parent > process's console, even if there is one, and hence there's nowhere for > Cygwin to hook the standard file descriptors up to. > > Having said that, XP introduced the AttachConsole() function, which > allows hooking up to the parent's console by pasing > 'ATTACH_PARENT_PROCESS' as the paremeter. That doesn't work as expected. I found that GetStdHandle does not return INVALID_HANDLE_VALUE. Rather, the handle looks like a normal console handle. Calling GetFileType then returns FILE_TYPE_UNKNOWN and GetLastError () returns ERROR_INVALID_HANDLE. I used that to add this code: Index: dtable.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/dtable.cc,v retrieving revision 1.221 diff -u -p -r1.221 dtable.cc --- dtable.cc 5 May 2011 22:30:53 -0000 1.221 +++ dtable.cc 23 May 2011 15:35:49 -0000 @@ -282,7 +282,10 @@ dtable::init_std_file_from_handle (int f char name[NT_MAX_PATH]; name[0] = '\0'; if (ft == FILE_TYPE_UNKNOWN && GetLastError () == ERROR_INVALID_HANDLE) - /* can't figure out what this is */; + { + if (AttachConsole (-1) || GetLastError () == ERROR_ACCESS_DENIED) + dev = *console_dev; + } else if (ft == FILE_TYPE_PIPE) { int rcv = 0, len = sizeof (int); In thoery that should attach to the console and open the console handles for stdin/out/err. The effect: - Started from CMD, XWin prints log output to the console. - Started from bash or tcsh, no output. - Mintty doesn't start at all. That doesn't look overly promising. It might be better if XWin itself tries the AttachConsole/CreateFile("CONOUT$") thingy instead, otherwise we might end up with some overly complex startup code(*) just for the benefit of a single application. Corinna (*) Insert "which already is overly complex" here. -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple