delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/01/25/10:12:48

X-Spam-Check-By: sourceware.org
Message-ID: <2578646.post@talk.nabble.com>
Date: Wed, 25 Jan 2006 07:12:27 -0800 (PST)
From: "Adam 13 (sent by Nabble.com)" <lists AT nabble DOT com>
Reply-To: Adam 13 <alb23 AT dl DOT ac DOT uk>
To: cygwin AT cygwin DOT com
Subject: Coprocesses/piping problem
MIME-Version: 1.0
X-Nabble-Sender: Nabble Forums <lists AT nabble DOT com>
X-Nabble-From: Adam 13 <alb23 AT dl DOT ac DOT uk>
X-IsSubscribed: yes
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

Hi,
I have been given some code which needs to run under Cygwin's version of bash. It uses a pair of pipes to drive a co-process, in what I'm told is a fairly standard way, detailed in the Interprocess Communication chapter of "Advanced Programming in the Unix Environment" by W.Richard Stevens.

(An uncommented :o( sample of some of the source is below this message.)

 Unfortunately, the program appears to hang when compiled and run, though the child process is launched. What is really bizarre is that this code works fine when compiled under Linux. Are there any pitfalls to be particularly aware of when trying to use this construct? Is this an area in which Cygwin may not be 100% POSIX compliant?
Thanks...

void CCoProcess::Process()
  {
    

    pid_t pid;
    
    if( (m_pid = pid = fork()) < 0)
      {
	std::cout << "fork error" << std::endl;
      }
    else if(pid > 0) 
      {			
	std::cout << "process started : child pid is"  << m_pid << std::endl;
	close(fd1[0]);
	close(fd2[1]);
      } 
    else 
      {									/* child */
	close(fd1[1]);
	close(fd2[0]);
	if (fd1[0] != STDIN_FILENO) 
	  {
	    if (dup2(fd1[0], STDIN_FILENO) != STDIN_FILENO)
	      {
		std::cout << "dup2 error to stdin" << std::endl;
	      }
	    close(fd1[0]);
	  }
	if (fd2[1] != STDOUT_FILENO) 
	  {
	    if (dup2(fd2[1], STDOUT_FILENO) != STDOUT_FILENO)
	      {
		std::cout << "dup2 error to stdout" << std::endl;
	      }
	    close(fd2[1]);
	  }
	if (m_vEnvironment.size() == 0)
	  {
	    if (execl(m_strPath.c_str(),m_strCommand.c_str(), (char *) 0) < 0)
	      {
		std::cout << "execl error" << std::endl;
	      }
	  }
	else
	  {
	    std::vector ::const_iterator itEnvironment = m_vEnvironment.begin();
	    int nEnvironmentCount = 0;
	    while(itEnvironment != m_vEnvironment.end())
	      {
		strcpy(m_cEnvironment[nEnvironmentCount++],(*itEnvironment++).c_str());
	      }
	    
	    m_cEnvironment[nEnvironmentCount] = 0;

	    if (execle(m_strPath.c_str(),m_strCommand.c_str(), (char *) 0,m_cEnvironment) < 0)	    
	      {
		std::cout << "value is : " << m_cEnvironment[0]  << std::endl;
		std::cout << "execle error" << std::endl;
	      }
	  }
      }
    
  }
--
View this message in context: http://www.nabble.com/Coprocesses-piping-problem-t995662.html#a2578646
Sent from the Cygwin Users forum at Nabble.com.


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