0

I have written a python which used to take values from command line and process the same. 5 variables are taken using raw_input() and in each case something is returned to screen.

I want this whole interaction to happen via php program which calls my python program. They are supposed to exchange variables more than one time.

I have read the possible solutions like running the python through php via shell and passing arguments. But I am not sure how once I start my python program I can simply keep on sending variables to it so that my python program reaches its logical end by getting variables from php.

  • 1
    [exec](http://php.net/manual/en/function.exec.php) would be a great start, you need to try something. – hassan Apr 08 '17 at 12:05
  • You mention that Python program would want to keep receiving variables. Is it fair to assume that the PHP program knows in advance what those variables would be? If those aren't very many, maybe you can supply them as an array? For instance model your `exec()` call to suit [this](http://stackoverflow.com/q/7605631/2298301)? Or maybe write them in a file which could then be read by the Python program? Or use a DB? A lot depends on what might sound most reasonable to you. – Dhruv Saxena Apr 08 '17 at 12:15
  • Thanks Dhruv. Files and DB are options for sure. I was thinking something which is much faster and lighter. All the variables will be strings but the real values would be dynamically received hence the need to pass them to python often and in toto. – Nrupal Das Apr 08 '17 at 19:56

1 Answers1

1

you have to use an IPC mechanism like file, pipe, named pipe, shared memory,... http://en.wikipedia.org/wiki/Inter-process_communication

You can generally communicate between languages by using common language formats, and using stdin and stdout [pipe] to communicate the data.

from: http://www.stackoverflow.com/questions/14047979/executing-python-script-in-php-and-exchanging-data-between-the-two

ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • Thanks Ralf. Yes I had seen this answer. It sends the initially data via json but I was not sure about subsequent data exchanges between the two programs. – Nrupal Das Apr 08 '17 at 19:51