delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/10/08/17:39:56

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=0.0 required=5.0 tests=AWL,BAYES_50,RP_MATCHES_RCVD,SPF_NEUTRAL
X-Spam-Check-By: sourceware.org
Message-ID: <4E90C308.9090508@cornell.edu>
Date: Sat, 08 Oct 2011 17:39:20 -0400
From: Ken Brown <kbrown AT cornell DOT edu>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Problem redirecting stderr to pipe in subprocess
References: <4E906DD1 DOT 50107 AT cornell DOT edu>
In-Reply-To: <4E906DD1.50107@cornell.edu>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
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

--------------040104070603080207080303
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

On 10/8/2011 11:35 AM, Ken Brown wrote:
> The attached STC arose from my attempt to understand the problem
> discussed starting in
>
> http://cygwin.com/ml/cygwin/2011-09/msg00405.html .
>
> I'm starting a new thread because there appears to be a Cygwin problem
> having nothing to do with emacs.
>
> The STC creates a pipe and then runs `bash -ic ls' in a subprocess, with
> both stdout and stderr sent to the pipe. The parent process reads from
> the pipe and echoes it to the terminal.
>
> On Linux, I first get the error messages (presumably expected)
>
> bash: cannot set terminal process group (-1): Invalid argument
> bash: no job control in this shell
>
> followed by the directory listing. On Cygwin, the bash process produces
> no output but is simply stopped, and I have to kill it from another
> terminal before the main program will exit. This happens both with
> cygwin-1.7.9 and the latest snapshot. Here are a few comments:
>
> 1. The problem disappears if I don't send bash's stderr to the pipe.
>
> 2. The problem also disappears if I replace -ic by -c in the call to
> bash, presumably because there's nothing sent to stderr in that case.
>
> 3. The problem disappears if I don't use a pipe but just have the bash
> subprocess write to the terminal, even if I redirect bash's stderr to
> stdout.

Attached is a slight modification of the STC, in which I set stdin for 
the bash subprocess to /dev/null.  With this modification, the program 
works as expected (and as on Linux) with cygwin-1.7.9, but the same 
problem as before occurs with the latest snapshot.

Ken


--------------040104070603080207080303
Content-Type: text/plain;
 name="bash-ls1.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="bash-ls1.c"

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

int
main()
{
  char  *argv[4];
  char buf;
  int fd[2];
  int nullfd = open ("/dev/null", O_RDONLY);
  pid_t  pid;

  argv[0] = "bash";
  argv[1] = "-ic";
  argv[2] = "ls";
  argv[3] = '\0';

  pipe (fd);

  pid = fork();
  if (pid == 0)
    {
      setsid ();

      close (0);
      close (1);
      close (2);
      dup2 (nullfd, 0);
      dup2 (fd[1], 1);
      dup2 (fd[1], 2);
      close (fd[1]);
      close (nullfd);
      execvp (argv[0], argv);
    }

  close (fd[1]);
  close (nullfd);
  while (read (fd[0], &buf, 1) > 0)
    write (1, &buf, 1);
  close (fd[0]);
}



                


--------------040104070603080207080303
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


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