Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 677331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:01:40+00:00 2026-05-14T01:01:40+00:00

I got some problems with EOF and stdio in a communication pipeline between a

  • 0

I got some problems with EOF and stdio in a communication pipeline between a python process and a C++ program. I have no idea what I am doing wrong. When I see an EOF in my program I clear the stdin and next round I try to read in a new line. The problem is: for some reason the getline function immediatly (from the second run always, the first works just as intended) returns an EOF instead of waiting for a new input from the python process… Any idea?

alright Here is the code:

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;

int main(int argc, char **argv) {
    for (;;) {
        string buf;
        if (getline(cin,buf)) {
            if (buf=="q") break;
            /*****///do some stuff with input //my actual filter program
            cout<<buf;
            /*****/
        } else {
            if ((cin.rdstate() & istream::eofbit)!=0)cout<<"eofbit"<<endl;
            if ((cin.rdstate() & istream::failbit)!=0)cout<<"failbit"<<endl;
            if ((cin.rdstate() & istream::badbit)!=0)cout<<"badbit"<<endl;
            if ((cin.rdstate() & istream::goodbit)!=0)cout<<"goodbit"<<endl;
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max());

            //break;//I am not using break, because I
                    //want more input when the parent
                    //process puts data into stdin;
        }
    }

    return 0;
}

and in python:

from subprocess import Popen, PIPE
import os
from time import sleep

proc=Popen(os.getcwd()+"/Pipingtest",stdout=PIPE,stdin=PIPE,stderr=PIPE);

while(1):
  sleep(0.5)

  print proc.communicate("1 1 1")
  print "running"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:01:40+00:00Added an answer on May 14, 2026 at 1:01 am

    communicate in python is a one shot function. It sends the given input to a process, closes the input stream, and reads the output streams, waiting for the process to terminate.

    There is no way you can ‘restart’ the pipe with the same process after “communicating”.

    Conversely, on the other side of the pipe, when you read EOF there is no more data to read. Any attempt to read will immediately return EOF; python has closed the pipe.

    If you want to carry on communicating with the same pipe you need to use the subprocess’ stdin and stdout members and not communicate (but be careful of the potential of deadlocks) and use something other than the end of stream to signal that the C++ side should do another “batch” of processing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got some problems in Datagrid WPF I have a datagrid, and I want
i've got some problems using jQTouch. I have this Link <a href=#site_map class=swap>Map</a> and
I am learning to use mysql.So, I got some problems. I have three table
I've got some problems with a table layout I used to show communication data
I have some problems with ajax responses. Everything is working okay, however I got
I have got some problems with plotting a sliced DataFrame with entire columns filled
got some problems. Built an applet that has to be used step-by-step. After each
got some problems deploying a java web application on jboss 7.1... Stepped through the
I got some problems here, I can't make my find_by_sql request to render an
i got some problems with my history listview. on logcat it stated the cause

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.