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.

3
  • 1
    exec would be a great start, you need to try something. Commented Apr 8, 2017 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? 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. Commented Apr 8, 2017 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. Commented Apr 8, 2017 at 19:56

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.