Subject: Re: Reading and writing to a cygwin terminal from a WINMAIN() windows application?
From: Jim Marshall <[email-masked]>
To: [email-masked]
Date: Thu, 29 Nov 2007 14:04:02 -0500
Newsgroups: gmane.os.cygwin
List-Id: <cygwin.cygwin.com>

Josef Karthauser wrote:
> Hi there,
> 
> I'm writing a windows "winmain()" application which talks to the
> console, and am having trouble getting it to write() to a cygwin console
> window.  I was hoping that someone on this list might be able to aid me.
> 
> The application is a dual graphics/CLI program, and so needs to detect
> whether it is running in a terminal first.  If it is then it runs in
> console mode, otherwise it opens a graphics window (using directx).  As
> such it has a winmain() instead of a main(), and therefore the
> stdin/stdout channels aren't immediately available to it.
> 
> Here's what it does:
> 
> 	// If we can attach to the parent terminal then we were run in a
> console window.
> 	if (AttachConsole(ATTACH_PARENT_PROCESS))
> 	{
> 		m_CLIApp = true;
> 	}
Have you tried to call GetLastError to see why the attach fails?
> 
> 	...
> 
> 	If (m_CLIApp) {
> 		// XXX Test output to the console.  Why doesn't this
> approach work in a cygwin console window?
> 		// XXX Where does the output go in that case?
> 		char s[] = "This is the console\r\n";
> 		unsigned long cChars;
> 		WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), s,
> lstrlen(s), &cChars, NULL);
> 	}
> 
> Does anyone know why this doesn't output to a cygwin console, although
> it does if started in a cmd shell?
> 
> Joe
> 

--
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/