Originally Posted by
Elkvis
I believe that error means that the pipe has been closed at one end.
yes I figured it out..well,besides that error that doesn't appear any more,the parent only manages to write to the pipe and read from it only once.That means that while the parent does:
Code:
//parent sends s (message) to the bidirectional pipe
cout<<s<<endl;
//parent reads any data the child sends
//cin is due to dup2 that has been used
getline(cin, str, '\0');
//parent writes everything that was received by the child through the
//bidirectional pipe to a file
myfile << str<<endl;
the child does:
Code:
//reads message s from the bidirectional pipe which has been sent //from the parent
cin.getline(s,LINESIZE);
//then the child reads data from an ifstream and writes them to the bidirectional pipe for the parent to receive that data
while(if.getline(line,LINESIZE))
cout<<line<<endl;
everything works fine for one loop.That means
parent writes message to pipe--->child reads message from pipe--->child writes many data to pipe--->parent reads all data the child sent through the pipe
but when I try to send a new message from the parent process the whole thing seems to reach a deadlock..
The way I try to send a message through the pipe again is the following:
Code:
for(int j=0;j<3;j++){
cout<<s<<endl;
getline(cin, str, '\0');
myfile << str<<endl;}
but as I said only goes on for one loop,for 3 loops as above it waits...