0

Is there a way, in Python, to run a single php syntax command? I know I can just run os.system to call a separate php file but that seem excessive. So I want no separate file if possible.

Something similar to:

if send_mail == True:
   #something to run single line php: mail($to,$txt,$subject)
11
  • 3
    Possible duplicate of Execute php code in Python Commented Jun 13, 2019 at 18:38
  • I want to do no separate file if possible. Commented Jun 13, 2019 at 18:47
  • @PhantomQuest How would $to, $txt, and $subject be getting values? Commented Jun 13, 2019 at 18:48
  • @PatrickQ Hard coding Commented Jun 13, 2019 at 18:50
  • @PhantomQuest If you don't want to import any modules, then os.system is all you have. Is there a particular reason why you don't want to import anything, even though subprocess is part of the python standard library (and thus comes pre-installed, along with all the other built-in tools)? Commented Jun 13, 2019 at 18:51

1 Answer 1

0

You can use subprocess library for doing this.

For example:


import subprocess

subprocess.call("php /path to php file")

I hope it helps.

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

1 Comment

This requires a call to a separate file, which I don't want if possible

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.