cgi integration question

Ken ken at hotmail.com
Fri Oct 11 08:34:17 EDT 2002


"Gerhard Häring" <gerhard.haering at opus-gmbh.net> wrote in message
news:slrnaqdgb7.164.gerhard.haering at haering.opus-gmbh.net...
> Ken <ken at hotmail.com> [2002-10-11 12:03 GMT]:
> > Hi there, I have a question on integration with python and C++.
> >
> > I have 2 sets of code. Python is used to display interface and C++ is
used
> > for backend execution. The executed result is saved to file so the
python can
> > read it and display back on the screen.
> >
> > When I execute the python  program:
> >
>
> > 1. How do I make the python to initiate execution of the C++ program and
pass
> >    over values/arguments?
> >
> > 2. How does python know when the C++ program finished execution so it
can
> >    open the result file to read from?
>
> No need for intermediary files, just use os.popen*.
>
> Here's a simple example:
>
> >>> import os
> >>> outf, inf = os.popen2("cat")
> >>> print >>outf, "hi"
> >>> outf.close()
> >>> print inf.read()
> hi
>
> outf is a stream to write to your child process (in this example, the Unix
cat
> utility, which will just duplicate on stdout what it gets on stdin). After
> writing the "parameters" to cat's stdin, I close it (don't ask me why
that's
> necessary, but this is the way it works :-D). Then, I read the whole
output of
> cat and print it.
>
> HTH,
>
> -- Gerhard

Hi, can you explain what is "inf" and "popen2" in:
outf, inf = os.popen2("cat")   ?

Is "cat" suppose to be a program name for me to call?

So.... if I get the idea right, my program should look like this:
import os
outf, inf = os.popen2("cat")
print >>outf, "hi"
outf.close()
print inf.read()  # does this mean  read from file?
=====

and the backend c++ program look somethingl like this:
executable filename: cat

#include <iostream>
using namespace std;

int main (int argc, char** argv) {
      cout << "value from argv"<< endl;
      return 0;
}

Still don't get how values are passed to the backend though....can you
please explain.... : (

Thanks






More information about the Python-list mailing list