From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15094 invoked by alias); 23 May 2011 15:40:27 -0000 Received: (qmail 12365 invoked by uid 22791); 23 May 2011 15:40:02 -0000 X-Spam-Check-By: sourceware.org Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.83/v0.83-20-g38e4449) with ESMTP; Mon, 23 May 2011 15:39:47 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id A6D992CA81E; Mon, 23 May 2011 17:39:44 +0200 (CEST) Date: Mon, 23 May 2011 15:40:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: CYGWIN=tty round 2 Message-ID: <20110523153944.GM3051@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <20110522211906.GA13428@ednor.casa.cgf.cx> <1306119201.4572.4.camel@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@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2011-05/txt/msg00331.txt.bz2 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