0

I have a python script on local machine sending data to PHP script on google cloud compute engine. I want my PHP script to send that data to another python script as arguments for processing. I am trying this, php script

<?php
$time = $_GET['time'];
exec("python3 caller.py ".$time,$output);
ar_dump($output);
echo $output;
?>
aloo_matar
  • 13
  • 5

3 Answers3

0

Did you try to look up shell_exec http://php.net/manual/en/function.shell-exec.php and PHP shell_exec() vs exec() ?

In addition i cant see your dir structure but php will probably require you to declare where from you execute your scripts. http://php.net/manual/en/function.dir.php

Gracz
  • 22
  • 3
  • Still no luck, PHP is not calling python. using, shell_exec("python3 /var/www/html/caller.py"); #no arguments – aloo_matar Feb 26 '19 at 14:37
0

You need to pass variables like below

$prog = 'pathtopythonfile/filename.py '.$variable1.' '.$variable2;
shell_exec($prog);

inside python file, u can get variables like below

import sys

var1 = sys.argv[1]
var2 = sys.argv[2]
PushpikaWan
  • 2,437
  • 3
  • 14
  • 23
0

I cant add comments at the moment so you could see this as a comment: What output do you get or do you get any errors? You're asking for help but not saying what's wrong.

Also there is a system function in php for this case: http://php.net/manual/en/function.system.php

$output = system("python3 caller.py ".$time, $executioncode);
main.c
  • 169
  • 2
  • 15
  • php is not even calling python. no error, no output. Otherwise, python would have made changes in my database. – aloo_matar Feb 26 '19 at 14:39