pipes

Y

yagyala

Hi. I'm trying to communicate with a c++ executable via pipes. I
prefer not to use forks because I want it to work on windows. In
python the code looks roughly like:

(r,w) = pipes()
spawnl(P_WAIT, 'tool.exe', 'dummy', message, str(w))
close(w)
print os.read(r, 1000)
close r

and in c++

int main (int argc, char**argv)
{
......
filedescriptor = atoi(argv[2]);
message = argv[1];
FILE * stream = fdopen(filedescriptor, "a");
cout << fputs(stream, message) << endl;
.....
return 0;

}

Sorry for any obvious errors, but I have neither the code nor my c++
reference handy, and I'm quite tired.
When I run the program the line " cout << fputs(stream, message) <<
endl", prints '0', indicating that I am writing to the file. I try
closing the file to be sure it is being flushed. I think I've tried
flushing it while leaving it open to be sure it isn't destroyed. But
no matter what I do, 'message' just sin't getting written back to the
pipe, or at least the python code isnt getting it. If I don't close w
after calling the c++ code the program hangs without responding to
input.

Do I need to be doing this across two processes (ie forking) ? Any
ideas?
Thanks
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top