conveyor non-stop

A

Andrew Wingorodov

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;
}
}
}
 
F

Flash Gordon

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.
 
A

Andrew Wingorodov

Flash Gordon said:
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
 
C

CBFalconer

Andrew said:
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++.
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top