I'm working on a python plugin & it needs to retrive some data from php script, As I tried below I can retrive php output as shell command,
But I need to call start() function from my python script by passing values as start(10,15)
Is there a possible way to call start() php function with parameters from python script ?
PHP Script:
<?php
function start($height, $width) {
return $height*$width;
}
echo start(10,15); // #1
?>
Python Script:
import subprocess
result = subprocess.run(
['php', './check1.php'], # program and arguments
stdout=subprocess.PIPE, # capture stdout
check=True # raise exception if program fails
)
print(result.stdout) # result.stdout contains a byte-string
CodePudding user response:
You can pass command-line arguments to a PHP script. See https://www.php.net/manual/en/reserved.variables.argv.php
PHP:
...
echo start($argv[1], $argv[2]);
Python:
result = subprocess.run(
['php', './check1.php', '10', '15'],
stdout = subprocess.PIPE,
check=True
)