1

I use the subprocess object in Python to invoke a PHP script. The script runs just fine and I can get the output from the process.

import subprocess

proc = subprocess.Popen("php /route/to/my/script/php", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()

However, I require to send some parameters to the script. How can I do this. I would assume I need to send a post via one of the parameters of Popen?

1 Answer 1

2

I think you should use args in the terminal:

Imagine you want to pass String arguments arg1, arg2 and arg3.

Your python class then should look like

proc = subprocess.Popen("php /route/to/my/script/php arg1 arg2 arg3", shell=True, stdout=subprocess.PIPE)

then the vardump of for the parameters would look like

<?php var_dump($argv);  ?>

and would return:

array(4) {
  [0]=>
  string(10) "script.php"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}

So thats how you could add parameers

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

Comments

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.