delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/11/29/04:12:21

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
X-VirusChecked: Checked
X-Env-Sender: joe DOT karthauser AT geomerics DOT com
X-Msg-Ref: server-6.tower-134.messagelabs.com!1196327513!38855502!13
X-StarScan-Version: 5.5.12.14.2; banners=-,-,-
MIME-Version: 1.0
Subject: Reading and writing to a cygwin terminal from a WINMAIN() windows application?
Date: Thu, 29 Nov 2007 09:10:52 -0000
Message-ID: <F5114451B5F49649A9337243D4F8E46908846FA0@THHS2EXBE1X.hostedservice2.net>
From: "Josef Karthauser" <joe DOT karthauser AT geomerics DOT com>
To: <cygwin AT cygwin DOT com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Note-from-DJ: This may be spam
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id lAT9CAQm002061

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;
	}

	...

	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/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019