This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

How to initialize stdin and stdout


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@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]