delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/05/19/04:42:52

X-Spam-Check-By: sourceware.org
Message-ID: <446D84F0.80609@cwilson.fastmail.fm>
Date: Fri, 19 May 2006 04:42:24 -0400
From: Charles Wilson <cygwin AT cwilson DOT fastmail DOT fm>
User-Agent: Thunderbird 1.5.0.2 (Windows/20060308)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: [RFA] patch for run.exe -- ATTN: ago
References: <446C1803 DOT 2050901 AT cwilson DOT fastmail DOT fm> <1147949399 DOT 27157 DOT 38 DOT camel AT zipoli DOT prudsys DOT com>
In-Reply-To: <1147949399.27157.38.camel@zipoli.prudsys.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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

Alexander Gottwald wrote:

> Actually GetStdHandle seems to work with pipes.
> 
> run cat foo | less 
> cat foo | run cat | less 
> 
> but this does exit immediatly
> run cat | less 

...

> So the invisible console should provide stdin, stdout and stderr where
> stdout and stderr will discard any written data and stdin should never
> return data on read.

Nor should the "stdin" pipe ever be "ready" if select() is called on its 
read end.  I'm sure that ought to be true -- as long as run doesn't 
stuff any data into the write end of it.

> creating a pipe for stdin could be useful. maybe creating one for stdout
> and stderr which is always read too.
> 
> 
>    start.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
>    start.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
>    start.hStdError = GetStdHandle(STD_ERROR_HANDLE);
> 
>    HANDLE hpStdInput[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
>    HANDLE hpStdOut[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
> 
>    if (start.hStdInput == INVALID_HANDLE_VALUE)
>    {
>      CreatePipe(&hpStdInput[0], &hpStdInput[1], NULL, 0);
>      start.hStdInput = hpStdInput[0];
>    }
>    if (start.hStdOutput == INVALID_HANDLE_VALUE || start.hStdError == INVALID_HANDLE_VALUE)
>    {
>      CreatePipe(&hpStdOutput[0], &hpStdOutput[1], NULL, 0);
>      if (start.hStdOutput == INVALID_HANDLE_VALUE)
>        start.hStdOutput = hpStdOutput[1];
>      if (start.hStdError == INVALID_HANDLE_VALUE)
>        start.hStdError = hpStdOutput[1];     
>    }
>       
>    sec_attrs.nLength = sizeof (sec_attrs);
>    sec_attrs.lpSecurityDescriptor = NULL;
>    sec_attrs.bInheritHandle = FALSE;
> 
>    if (CreateProcess (NULL, cmdline, &sec_attrs, NULL, TRUE, 0,
>                       NULL, NULL, &start, &child))
>    {
>       if (wait_for_child)
>       {
>          if (hpStdOutput[0] != INVALID_HANDLE_VALUE)
>          {
>            HANDLE handles[2] = { child.hProcess, hpStdOutput[0] };
>            while (WaitForMultipleObjects (2, handles, FALSE, INFINITE) == WAIT_OBJECT_0 + 1)
>            {
>              char buffer[1024];
> 	     DWORD dwRead;
>              ReadFile (hpStdOutput[0], buffer, 1024, &dwRead, NULL);
>            }
>          } else {
>            WaitForSingleObject (child.hProcess, INFINITE);
>          }
>          GetExitCodeProcess (child.hProcess, &retval);
>       }
>       CloseHandle (child.hThread);
>       CloseHandle (child.hProcess);
>    }

Unfortunately this doesn't solve my problem (after disabling the 
setup_invisible_console() call).  There are two reasons:

(1) as it happens, GetStdHandle does *not*, in fact, return 
INVALID_HANDLE_VALUE.  I thought it would given my reading of the docs. 
  I thought it DID when I tested it.  But I was wrong.  It's returning 
some non-zero, non-INVALID_HANDLE_VALUE-value.  I have no idea why.

(2) Even if I force your pipe code to activate (by explicitly assigning 
INVALID_HANDLE_VALUE to start.hStdInput and friends at the top of the 
code block above), rxvt-unicode-X still goes haywire.

Sigh.  Hopefully I'll have time to look into this more over the weekend. 
Maybe something like
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp



> Anyway, if the allocated hidden console does not interfere with the
> pipes i'm going to add it.

???  the pipe code?  or the setup_invisible_console code?  or both?

> Is it possible to create a console on win9x and hide it again. This will
> flash, but at least it does work.

Well, yeah...but then you might as well not even use run.exe for 
launching rxvt or rxvt-unicode.  They can hide their console all by them 
selves, if you don't mind the brief flash.

--
Chuck

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