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