I've run into a slight issue with the way my site works. I have a python script which I want to run from the index.php page. Now if this script is in the root directory, by using this command I can execute it easily:
<?php
exec("myscript.py");
?>
This actually runs the python script and does what is needed. However, I am planning to have a few more script and want to keep the root dir as clean as possible, hence I was wondering if it is possible to execute this script from a subdir within my root?
Current Setup:
Root - C:\wamp\www\homepage\
Python Script Folder - ...\homepage\python\
When i put my scripts in the python folder, no matter what I use, the php does not execute it.
Tried:
<?php
exec("/python/myscript.py")
?>
<?php
exec("//python//myscript.py")
?>
<?php
exec("\python\myscript.py")
?>
<?php
exec("\\python\\myscript.py")
?>
<?php
exec("python/myscript.py")
?>
<?php
exec("python\myscript.py")
?>
<?php
exec("../python/myscript.py")
?>
All this and nothing launches the darn thing. What am I doing wrong :[
<?php
exec("C:/wamp/www/homepage/python/myscript.py")
?>
apple16 2012-04-04 22:22
Did you try calling the python executable directly? It worked for me. I had a myscript.py like this:
print 'hello'
print 'world'
and then put it in a directory called temp/.
My php is in a file called temp.php as follows:
<?php
exec('python temp/myscript.py',$output);
print_r($output);
?>
Then I ran it and here's what happened:
$ php temp.php
Array
(
[0] => hello
[1] => world
)
exec("python/myscript.py")
should work. But tryexec(__DIR__ . "/python/myscript.py")
binarious 2012-04-04 19:51