Endless problems with a very simple python subprocess.Popen task
Posted
by Thomas
on Stack Overflow
See other posts from Stack Overflow
or by Thomas
Published on 2010-04-23T19:19:52Z
Indexed on
2010/04/23
19:43 UTC
Read the original article
Hit count: 412
python
|subprocess
I'd like python to send around a half-million integers in the range 0-255 each to an executable written in C++. This executable will then respond with a few thousand integers. Each on one line. This seems like it should be very simple to do with subprocess but i've had endless troubles. Right now im testing with code:
// main()
u32 num;
std::cin >> num;
u8* data = new u8[num];
for (u32 i = 0; i < num; ++i)
std::cin >> data[i];
// test output / spit it back out
for (u32 i = 0; i < num; ++i)
std::cout << data[i] << std::endl;
return 0;
Building an array of strings ("data"), each like "255\n", in python and then using:
output = proc.communicate("".join(data))[0]
...doesn't work (says stdin is closed, maybe too much at one time). Neither has using proc.stdin and proc.stdout worked. This should be so very simple, but I'm getting constant exceptions, and/or no output data returned to me. My Popen is currently:
proc = Popen('aux/test_cpp_program', stdin=PIPE, stdout=PIPE, bufsize=1)
Advise me before I pull my hair out. ;)
© Stack Overflow or respective owner