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)" Reply-To: Adam 13 To: cygwin AT cygwin DOT 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 X-Nabble-From: Adam 13 X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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/