conveyor non-stop

Discussion in 'C Programming' started by Andrew Wingorodov, Dec 28, 2007.

  1. Hi, folks

    I wish to make the conveyor, but i can't receive the answer
    before I shall close a pipe.

    For example:

    int
    main ()
    {
    int rpipe [2];
    int wpipe [2];

    ::pipe (rpipe);
    ::pipe (wpipe);

    pid_t _pid;

    enum { RD, WR };

    if (0 == (_pid=::fork()))
    {
    ::close (rpipe [WR]);
    ::dup2 (rpipe [RD], STDIN_FILENO); // read rpipe through stdin
    ::close (rpipe [RD]);

    ::close (wpipe [RD]);
    ::dup2 (wpipe [WR], STDOUT_FILENO); // write stdout to wpipe
    ::close (wpipe [WR]);

    ::execl ("/usr/bin/tr", "tr", "A-Z", "a-z", 0);
    cout << ::strerror (errno) << endl;
    return errno;

    } else {
    ::close (rpipe [RD]);
    ::close (wpipe [WR]);

    std::string line;
    while ( std::getline (cin, line)) {

    ::write ( rpipe [WR], line.c_str(), line.size () );
    ::write ( rpipe [WR], "\n" , sizeof("\n") );
    ///::close ( rpipe [WR]);

    /// With close() I read; without close() I blocked
    /// But close() destroy my cool conveyor!
    /// How to me to avoid it?

    char buf [1024];
    int n = ::read ( wpipe [RD], buf, 1024 );
    buf [n] = '\0';

    cout << buf << endl;
    }
    }
    }

    --
    www.andr.mobi
    Andrew Wingorodov, Dec 28, 2007
    #1
    1. Advertising

  2. Andrew Wingorodov

    Flash Gordon Guest

    Andrew Wingorodov wrote, On 28/12/07 12:58:
    > Hi, folks
    >
    > I wish to make the conveyor, but i can't receive the answer
    > before I shall close a pipe.
    >
    > For example:
    >
    > int
    > main ()
    > {
    > int rpipe [2];
    > int wpipe [2];
    >
    > ::pipe (rpipe);
    > ::pipe (wpipe);


    <snip>

    This is definitely not C. It could be C++, but that is a different
    language. It could also be an extension to C++. I suggest probably
    either comp.unix.programmer or comp.lang.c++ would be better places to
    ask depending on whether my guess that is a POSIX extension is correct
    or whether you are using standard C++. However, before posting in one of
    those groups do what you failed to do here, i.e. actually check what the
    group is about.
    --
    Flash Gordon
    Flash Gordon, Dec 28, 2007
    #2
    1. Advertising

  3. Flash Gordon <> wrote:
    >
    > This is definitely not C. It could be C++, but that is a different


    I speak C - I mean UNIX
    I speak UNIX - I mean C

    (c)

    > those groups do what you failed to do here, i.e. actually check what the
    > group is about.


    i so sorry
    never mind

    --
    www.andr.mobi
    Andrew Wingorodov, Dec 28, 2007
    #3
  4. Andrew Wingorodov

    CBFalconer Guest

    Andrew Wingorodov wrote:
    >
    > I wish to make the conveyor, but i can't receive the answer
    > before I shall close a pipe.
    >
    > For example:
    >
    > int main () {
    > int rpipe [2];
    > int wpipe [2];
    >
    > ::pipe (rpipe);
    > ::pipe (wpipe);


    This is not C. I suspect you want comp.lang.c++.

    --
    Merry Christmas, Happy Hanukah, Happy New Year
    Joyeux Noel, Bonne Annee, Frohe Weihnachten
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Dec 28, 2007
    #4
    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. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    710
    Matt Theule
    Jul 24, 2003
  2. Son KwonNam
    Replies:
    11
    Views:
    2,573
    mr_organic
    Apr 9, 2004
  3. Will
    Replies:
    1
    Views:
    15,169
    Thomas Weidenfeller
    Nov 2, 2004
  4. Edje
    Replies:
    0
    Views:
    104
  5. Replies:
    0
    Views:
    643
Loading...

Share This Page