Redirect of stdout to pipe 'hangs'

Discussion in 'C++' started by seema_coma@yahoo.co.in, Aug 12, 2005.

  1. Guest

    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
     
    , Aug 12, 2005
    #1
    1. Advertising

  2. John Ratliff Guest

    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,
    >
    > 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
     
    John Ratliff, Aug 12, 2005
    #2
    1. Advertising

  3. 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,
    >
    > 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).
     
    Maxim Yegorushkin, Aug 12, 2005
    #3
  4. wrote:

    []

    > Can somebody please explain how to fix it?


    Try using less instead of more.
     
    Maxim Yegorushkin, Aug 12, 2005
    #4
  5. Guest

    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?
     
    , Aug 12, 2005
    #5
  6. wrote:
    > 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?
     
    Maxim Yegorushkin, Aug 12, 2005
    #6
  7. Guest

    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.
     
    , Aug 12, 2005
    #7
  8. Flash Gordon Guest

    Maxim Yegorushkin wrote:
    > wrote:
    >
    >>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?


    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.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Aug 12, 2005
    #8
  9. wrote:
    > 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.
     
    Maxim Yegorushkin, Aug 12, 2005
    #9
  10. Joe Wright Guest

    wrote:
    > 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.

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
     
    Joe Wright, Aug 12, 2005
    #10
  11. SM Ryan Guest

    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.

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    God's a skeeball fanatic.
     
    SM Ryan, Aug 12, 2005
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lee, wonsun
    Replies:
    1
    Views:
    490
    Jack Klein
    Nov 2, 2004
  2. Elad
    Replies:
    0
    Views:
    415
  3. Replies:
    11
    Views:
    547
    akarl
    Aug 13, 2005
  4. Sal
    Replies:
    1
    Views:
    547
  5. Replies:
    1
    Views:
    227
    Ben Morrow
    Jun 2, 2004
Loading...

Share This Page