delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/07/11/19:21:15

From: root AT jacob DOT remcomp DOT fr (root)
Subject: How to initialize stdin and stdout
11 Jul 1997 19:21:15 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <m0wmlqZ-000AK2C.cygnus.gnu-win32@jacob.remcomp.fr>
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

Recently I asked about using the console when spawning a child
process. After almost a week of hard work, I have discovered many bugs
in the implementation of lcc's runtime, and I thought this would be
interesting to some people here, since the minimalist version of gcc
has the same bug probably.

The problem starts when you forget to take into account the 
STARTUP_INFORMATION at program's startup. The minimalist version (and
lcc's runtime) do the same thing: They call open_osfhandle with
the codes for STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, and STD_ERROR_HANDLE.
Using the obtained integer handle, they call fdopen, and assign the
result to stdin, stdout and stderr. This is WRONG if the program has
been started with its output channels redirected to a pipe. The program
should call GetStartupInfo with the address of a structure STARTUP_INFORMATION
and test the flags field. If the bit STARTF_USESTDHANDLES is set, this
means that the fields hStdInput, hStdOutput and hStdError are valid
and THEY should be used, instead of the procedure above.

GUI process CAN use a console. I understood that Sergey answered that this
isn't possible. That is wrong, because I use 'AllocConsole' and it works.
A horrible window with black background opens. There is no way to change
its position but those are minor aesthetic 'bugs'.

Another interesting point is that is possible to stop a program with the
API GenerateConsoleCtrlEevent. Now it works, since I did an AllocConsole.
When you type Ctrl-C in the console window, the process stops.

It is important that the 'make.exe' process is created with the
CREATE_NEW_PROCESS_GROUP flag, since this flag propagates the Ctrl-C to
the child process, i.e. the compiler spawned by the make.
make.exe shuld be modified to setup a Ctrl-C handler. I have read some
messages with Ctrl-C problems using gnu make, and maybe this is the reason
for those bugs.

Sorry for this long message.

-- 
Jacob Navia	Logiciels/Informatique
41 rue Maurice Ravel			Tel 01 48.23.51.44
93430 Villetaneuse 			Fax 01 48.23.95.39
France
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


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