slash89mf
slash89mf

Reputation: 1067

Execute python script with output from php

Is there any special permission or setting in order to execute a python script that create a new file or image? This is my code:

<?
function py(){
    exec( 'python my_script.py');
    echo "ok";
}

py();
?>

And this is my python script (an example):

#!/usr/bin/python
import sys

f = open('out.txt', 'w')
print >> f, 'thats all'
f.close()

Running php i get "ok" message but no file is created. What am i doing wrong?

Upvotes: 4

Views: 1985

Answers (2)

Mike Mannakee
Mike Mannakee

Reputation: 361

You need to call shell_exec() not exec() if you want to be able to capture the output:

Refernce: PHP Manual

Upvotes: 0

slash89mf
slash89mf

Reputation: 1067

Setting the right permissions to file and folders did the trick.

enter image description here

On Mac OS: Alt + Click on "+", then search for _www and add World Wide Web Server to users giving read and write permission. Same for the root folder.

Upvotes: 1

Related Questions