This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Coprocesses/piping problem


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]