-1

I want to run a Python script from PHP via system with some arguments. My PHP doesn't throw any errors and $retval is 1. But I don't see any generated output file $f1 in the current directory. Is there a chance the output file goes somewhere else?

$outp1 = system("python plain.py {$url1} {$f1}", $retval);
hakre
  • 193,403
  • 52
  • 435
  • 836
Dirk N
  • 717
  • 3
  • 9
  • 23
  • What happens when you use `shell_exec`? – Дамян Станчев Oct 18 '12 at 10:20
  • 3
    Please see [Terminal passing arguments from variable containing whitespace](http://stackoverflow.com/q/12925034/367456) - It looks like you do not really care about creating a safe command string, so it might be that you are not passing to the command what you think. – hakre Oct 18 '12 at 10:21
  • You need to debug the command, assign it to a variable first so you can print and review it. In case you're interested if the command itself generates error output to [*stderr*](http://en.wikipedia.org/wiki/Standard_streams), please see [PHP StdErr after Exec()](http://stackoverflow.com/q/2320608/367456) for multiple ways to achieve that. – hakre Oct 18 '12 at 10:29
  • It seems to work with a simpler script which just prints the time. $o=system("python t.py",$retval); echo $o; echo $retval; echo "python plain.py {$url1} {$f1}"; $outp1=system("python plain.py {$url1} {$f1}",$retval); echo $outp1; echo $retval; as you can see I print the command, output and retval; plus I checked the folder for the output file $f1 – Dirk N Oct 18 '12 at 12:20
  • There are no white spaces within string variables – Dirk N Oct 18 '12 at 12:22

1 Answers1

0

Found the answer now, I needed to set permissions to 777 so that apache can write to the folder.

Dirk N
  • 717
  • 3
  • 9
  • 23