473,396 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Linux named pipes programming problem

Hi all,

I'm new to the group and am seeking your advice on my Linux programming
problem.

Two programs are involved. One is myProgram.cc, which reads user's
input from keyboard and prints output to the screen. The other program
is main.cc, which wants to communicate with myProgram in real time
using input/output redirection and two named pipes.

Now the problem is that main.cc works fine in one machine (sun4u, OS
version 5.9, sparc, Ultra-60) but hangs in another machine running
Debian Linux--the execution falls into infinite waiting at the first
std::getline statement in main.cc. Could anyone suggest what the
problem might be? The two programs are as follows:
/*****************************************
myProgram.cc
*****************************************/
#include <iostream>
#include <fstream>
#include <string>

main(){
std::string strIn;
std::cout<<"Starting the myProgram.\n";
std::cout.flush();
for(int i=1;i<=10;i++){
std::cout<<"Iteration "<<i<<" out of 10. Please enter: \n";
std::cout.flush();
std::getline(std::cin,strIn,'\n');
std::cout<<"Your input "<<i<<" was: "<<strIn<<"\n";
std::cout.flush();
}
std::cout<<"\nEnd of myProgram.\n";
std::cout.flush();
return 2;
}

/*****************************************
main.cc
*****************************************/
#include <iostream>
#include <fstream>
#include <string>

std::fstream fin,fout;
std::string path,f1,f2,cmd,str, cmd1;

main(){
system("rm -rf sicsin");
system("rm -rf sicsout");
system("mknod sicsin p");
system("mknod sicsout p");

char *mycmd="./myProgram <sicsin 2>sicsout >sicsout &";
system(mycmd);
usleep(3);

fout.open("sicsin",std::ios::out);
if(!fout.is_open()) {
std::cout<<"\nsicsin not found.\n";
return 0;
}
std::cout<<"\nsicsin is opened.\n";

fin.open("sicsout",std::ios::in);
if(!fin.is_open()) {
std::cout<<"\nsicsout not found.\n";
return 0;
}
std::cout<<"\nsicsout is opened.\n";

int i;

for(i=1; i<=10; i++){
fout<<i<<i<<i<<i<<i<<i<<i<<i<<i<<i<<i<<i<<" from main.cc"<<std::endl;
fout.flush();
// /*Line A*/ }
// /*Line B*/ for(i=1; i<=10; i++){
std::getline(fin,str,'\n');
std::cout<<"\nThe content of line "<<i<<" is: "<<str<<"\n";
std::getline(fin,str,'\n');
std::cout<<"\nThe content of line "<<i<<" is: "<<str<<"\n";
}

std::getline(fin,str,'\n');
std::cout<<"\nThe content of the next line is: "<<str<<"\n";

std::getline(fin,str,'\n');
std::cout<<"\nThe content of the next line is: "<<str<<"\n";

std::getline(fin,str,'\n');
std::cout<<"\nThe content of the next line is: "<<str<<"\n";
std::cout<<"\nThis is the end of main.cc.\n";
return 2;
}
------------------------------------------------------------------------------------

The above program main.cc falls into infinite waiting at the first
std::getline statement when running on Debian Linux. However, if I
remove the "//" in Line A and Line B in main.cc, it will work fine. But
this solution is not what I want because it performs one-off write to
the pipe file rather than real time interactive write and read.

Thanks very much for any suggestion from you!
George

Dec 13 '05 #1
0 1743

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matt W | last post by:
Hi all, I just noticed this in the manual yesterday: http://www.mysql.com/doc/en/Windows_running.html "MySQL supports TCP/IP on all Windows platforms. The mysqld-nt and mysql-max-nt servers...
5
by: rajnish | last post by:
Hi Gurus, I am a newbee in C++ field. And I have been assigned to complete a task of create a template class, so that names pipes can be created using this template. I don't have a clue from...
5
by: glenn.owens | last post by:
In the process of doing some routine monitoring/clean-up we've discovered that several (many?) users are apparently set to access our SQL Server 2000 database instances via the Named Pipes...
2
by: Rudolf Bargholz | last post by:
Hi, DB2 7.1 FP11 Windows 2000 Earlier this evening, after dropping and recreating a trigger, DB2 locked up. I am not entirely sure that the cause of the problem was the replacing of the...
4
by: Ken Allen | last post by:
Is there any built-in facility for handling named pipes in C#/.Net, or must one use unsafe code to access the WIN32 API directly? There exists some code that uses named pipes heavily and there...
1
by: Jarrod Morrison | last post by:
Hi All Im looking for a way use named pipes between a service app and an app run when a user logs on and be able to pass string based data, im hoping that the service can contact the app that is...
14
by: Rochester | last post by:
Hi, I just found out that the general open file mechanism doesn't work for named pipes (fifo). Say I wrote something like this and it simply hangs python: #!/usr/bin/python import os
1
by: dgk | last post by:
I trying to use a named pipe but can't figure out how to get the callback to work: Module Module1 Private ps As System.IO.Pipes.NamedPipeServerStream Public Sub main()...
7
by: andrewb | last post by:
Hi all, Having some trouble using named pipes and Visual Basic .NET and would appreciate and help you could offer. Essentially I am trying to develop a simple client/server application that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.