Pipes bug when spawning non-cygwin processes

Takashi Yano takashi.yano@nifty.ne.jp
Fri Feb 21 01:01:00 GMT 2020


On Thu, 20 Feb 2020 14:33:27 -0500
Edward Lam wrote:
> On Tue, Feb 18, 2020 at 2:43 PM Takashi Yano wrote:
> > Could you please provide a simple test case?
> 
> Here you go:
> 
> // pipes.cpp
> //
> // Compile in a  Visual Studio x64 Native Tools Command Prompt:
> //     cl pipes.cpp /link /subsystem:windows
> //
> // Run from inside a Cygwin shell, the produced pipes.exe
> //
> 
> #include <stdio.h>
> #include <windows.h>
> 
> INT WinMain(HINSTANCE, HINSTANCE, PSTR, INT)
> {
>     printf("This message used to show up in mintty cygwin v.2.11.2 shell!
> or from ssh session\n");
>     return 0;
> }
> // end of pipes.cpp

Thanks for the test case. Indeed, this works upto cygwin 3.0.7,
and does not work in cygwin 3.1.0 or later.

However, I wonder what platform is your program for. This test
case does not work also in native windows command prompt.
Your test case works only in old cygwin pty.

If you want to make a program which works in cygwin pty, you
can use cygwin g++ like:
g++ -mwindows pipes.cpp -o pipes
The binary built by above command works in cygwin pty, but does
not work in cygwin console (cygwin in command prompt) even with
cygwin 3.0.7.

If you want to make a program which works with windows console,
you should change the code like:

INT WinMain(HINSTANCE, HINSTANCE, PSTR, INT)
{
    if (!AttachConsole(ATTACH_PARENT_PROCESS)) AllocConsole();
    freopen("CONOUT$", "w", stdout);
    printf("This message used to show up in mintty cygwin v.2.11.2 shell! or from ssh session\n");
    return 0;
}

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list