Unix questions - Re: conveyor non-stop

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > December 2007 > Re: conveyor non-stop





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: conveyor non-stop
Andrew Wingorodov

2007-12-28, 1:26 pm


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'm blocked
/// But close() destroy mine 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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com