public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Edward Lam <triplequadsupport@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Pipes bug when spawning non-cygwin processes
Date: Mon, 24 Feb 2020 14:46:00 -0000	[thread overview]
Message-ID: <CAJZe6MCnEbdZEup2PBm2MgvpJZKcmgWV5dy4tD3kVFnxBFOPEw@mail.gmail.com> (raw)
In-Reply-To: <20200221100121.44625484e94eef069f9ff3d8@nifty.ne.jp>

Hi,

Thank you for your reply.

On Thu, Feb 20, 2020 at 8:01 PM Takashi Yano <takashi.yano@nifty.ne.jp>
wrote:

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

I have a native graphical Windows application that relied on cygwin/mintty
providing stdout so that my printf's work.

I would contend that there's no reason for cygwin/mintty to work the same
as the native windows command prompt because the behaviour there is for it
to detach the child process. This is not the case when we run a graphical
process in a cygwin/mintty shell. The old behaviour was much welcome
because it allowed graphical applications that did not detach from the
console work just like on Linux.

I should note that there is also the odd behaviour that the child process
is created with an inherited stderr handle but when I try to write to it,
it doesn't show up anywhere. On the native windows command prompt, the
child process isn't even created with the inherit handles flag enabled.

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

This might not have worked in cygwin 3.0.07 because it's missing a
freopen("CONOUT$", "w", stdout). I had omitted this in my minimal test case
because I found that this was unnecessary when I built with Visual Studio.

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

Ah, I did not now about AttachConsole(ATTACH_PARENT_PROCESS).

The application that I ship out to my users cannot force the requirement of
having cygwin, nor is compiling with cygwin g++ an option. Is there some
way to have a non-cygwin app detect the presence of cygwin pty so that it
can behave differently? When the native command prompt detaches the child
process, the child process should not really write to the parent's console
and should allocate its own instead.

Thanks again,
-Edward

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

      parent reply	other threads:[~2020-02-24 14:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30 19:04 Edward Lam
2020-01-30 22:25 ` Takashi Yano
2020-01-31  6:25   ` Edward Lam
2020-02-18 19:24     ` Edward Lam
2020-02-18 19:43       ` Takashi Yano
2020-02-20 19:33         ` Edward Lam
2020-02-21  1:01           ` Takashi Yano
2020-02-21  1:08             ` Takashi Yano
2020-02-21  1:23               ` Takashi Yano
2020-02-24 14:46             ` Edward Lam [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJZe6MCnEbdZEup2PBm2MgvpJZKcmgWV5dy4tD3kVFnxBFOPEw@mail.gmail.com \
    --to=triplequadsupport@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).