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@nabble.com>
Reply-To: Adam 13 <alb23@dl.ac.uk>
To: cygwin@cygwin.com
Subject: Coprocesses/piping problem
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Nabble-Sender: Nabble Forums <lists@nabble.com>
X-Nabble-From: Adam 13 <alb23@dl.ac.uk>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.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/

