X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 In-Reply-To: <416096c60904051420h66325080j3b059f3fbb857bde@mail.gmail.com> References: <416096c60904051420h66325080j3b059f3fbb857bde AT mail DOT gmail DOT com> Date: Wed, 15 Apr 2009 16:14:13 +0100 Message-ID: <416096c60904150814y45976747qa7878d1ed256fc9@mail.gmail.com> Subject: Re: popup consoles on Windows 7 From: Andy Koppe To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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 I think I found the reason why consoles pop up for mintty and XWin on Windows 7. Cygwin's fhandler_console.cc uses a clever trick where it allocates a console on an invisible custom "window station". I tried to do the same in the mintty child process, but found that AllocConsole() no longer cares whether a custom window station has been selected with SetProcessWindowStation(): the console window is opened on the default window station anyway. Here's what I did, between forkpty() and exec(): DWORD version = GetVersion(); version = ((version & 0xff) << 8) | ((version >> 8) & 0xff); if (version >= 0x0601) { HWINSTA wst0 = GetProcessWindowStation(); HWINSTA wst = CreateWindowStation (NULL, 1, WINSTA_ALL_ACCESS, &sa); SetProcessWindowStation(wst); AllocConsole(); SetProcessWindowStation(wst0); CloseWindowStation(wst); } Debug output showed that the function calls all succeeded, and that CreateWindowStation() did create a station separate from the default one. No idea what to do about it ... Andy 2009/4/5 Andy Koppe: > MinTTY is a -mwindows app, which so far seemed to work well on XP and > Vista, because no console is popped up, not even momentarily. Not so > on Windows 7, unfortunately. forkpty() and execve() are used to create > the child process and invoke the command, whereby it appears to be the > exec call that causes a console to pop up. > > I guess the fact that rxvt is a CUI app explains why its trick for > creating a hidden console didn't work in MinTTY: rxvt opens that > console in the main process, which in a GUI app isn't passed down to a > child process. > > So here's what I've done instead in 0.4-beta1: call AttachConsole(-1) > to attach to any parent console from the main mintty process, and call > it again from the child process to pass it down to that. If there is > no console, create one using AllocConsole (in the child process), and > hide it using ShowWindowAsync. > > Unfortunately two problems have been reported with this. The console > isn't always hidden, and a really weird one on a 64-bit Windows 7: > when invoking mintty from a bash running in a console, that console > window locks up. I'm rather stuck on what to do about those, so > suggestions would be welcome. > > Also, a couple of questions. > > When mintty is invoked from a shortcut or the Run dialog, the main > process actually does get a console, i.e. GetConsoleWindow() returns a > handle, but it doesn't appear on the screen, and the child process > can't attach to it using AttachConsole(). When invoked from a console > or rxvt, GetConsoleWindow() returns null. What's the reason for that? > > Furthermore, I'd previously seen the popup console problem on an old > Cygwin install on XP, but updating cured it. So has this been > addressed in the Cygwin DLL in the past, and is it likely that it can > be solved for Windows 7 too? Any idea what might have changed in > Windows that causes this issue? > > Btw, XWin is affected by this too. Starting it from a shortcut on > Vista is fine, but on 7 multiple consoles pop up briefly, and one > stays up. > > Andy > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/