Redirect of stdout to pipe 'hangs'

S

seema_coma

Iam working on Client, Server programming on Linux in C++.
I have a Server Daemon running in the background, my client program
talks to the Server and extracts some data which I
am printing on the screen. This thing works fine but when i redirect
the stdout to pipe it hangs for eternity,

for example,

seema@coma> simple_client | more

If I 'kill' the Server Daemon, then control is eventually returned back
to the shell. I need to make it work because
i want to integrate executable with the shell script. Can somebody
please explain how to fix it?

Thanks in Advance
Seema
 
J

John Ratliff

Iam working on Client, Server programming on Linux in C++.
I have a Server Daemon running in the background, my client program
talks to the Server and extracts some data which I
am printing on the screen. This thing works fine but when i redirect
the stdout to pipe it hangs for eternity,

for example,

seema@coma> simple_client | more

If I 'kill' the Server Daemon, then control is eventually returned back
to the shell. I need to make it work because
i want to integrate executable with the shell script. Can somebody
please explain how to fix it?

Thanks in Advance
Seema

Please post your code if you want us to help you with it.

Also, please don't cross post. If you have a c++ language question, post
it here. If it's a c question, ask it in that newsgroup.

Rules for posting to this newsgroup are available at
http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c++.html

--John Ratliff
 
M

Maxim Yegorushkin

Iam working on Client, Server programming on Linux in C++.
I have a Server Daemon running in the background, my client program
talks to the Server and extracts some data which I
am printing on the screen. This thing works fine but when i redirect
the stdout to pipe it hangs for eternity,

for example,

seema@coma> simple_client | more

If I 'kill' the Server Daemon, then control is eventually returned back
to the shell. I need to make it work because
i want to integrate executable with the shell script. Can somebody
please explain how to fix it?

This is probably because more utility reads a whole file before
outputting it. So, here more does not produce any output until
simple_client closes its output stream (or exits closing all streams).
 
S

seema_coma

No man even if I use simple_client | less or simple_client | cat it
will hang.I suspect the issue is that the pipe is being attached to the
daemons, which do not exit immediately. Can somebody please help me to
solve this?
 
M

Maxim Yegorushkin

No man even if I use simple_client | less or simple_client | cat it
will hang.I suspect the issue is that the pipe is being attached to the
daemons, which do not exit immediately. Can somebody please help me to
solve this?

Is simple_client a daemon?
 
S

seema_coma

No its not, it is just a program which reads the response from the
server daemon 'simple_server'. if i kill simple_server daemon
simple_client returns the controle to shell otherwise, it hangs.
 
F

Flash Gordon

Maxim said:
Is simple_client a daemon?

None of this is on topic in comp.lang.c (and I doubt it is no topic in
comp.lang.c++) so please take this discussion else where. A group with
unix in the name might be a good start.
 
M

Maxim Yegorushkin

No its not, it is just a program which reads the response from the
server daemon 'simple_server'. if i kill simple_server daemon
simple_client returns the controle to shell otherwise, it hangs.

This is offtopic here.

You might like to move the discussion to comp.unix.programmer, people
there may well help you.
 
J

Joe Wright

No man even if I use simple_client | less or simple_client | cat it
will hang.I suspect the issue is that the pipe is being attached to the
daemons, which do not exit immediately. Can somebody please help me to
solve this?
Why are you people here? This is a C language newsgroup. Go find a group
related to whatever it is you are talking about. Maybe plumbing.
 
S

SM Ryan

(e-mail address removed) wrote:
# Iam working on Client, Server programming on Linux in C++.
# I have a Server Daemon running in the background, my client program
# talks to the Server and extracts some data which I
# am printing on the screen. This thing works fine but when i redirect
# the stdout to pipe it hangs for eternity,

If you're using <stdio.h>, you may have bufferring issues. You
can try using setvbuf or fflush to make sure output is actually
being written to the pipe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top