This question already has an answer here:
Closed 12 years ago.
Possible Duplicate:
Start local PHP script w/ local Python script
How do you execute a php file and then view the output of it?
os.system("php ./index.php")
Does not work only returns 0
What you need is the os.popen function. It runs the command and returns the stdout pipe for that commands output. You can also capture the stdin, stderr by using os.popen2, popen3
import os
outp = os.popen('php ./index.php')
text = outp.read() # this will block until php finishes
# and returns with all output in text
print text
If you're working under Windows, you can use os.startfile().
Related
This question already has answers here:
How can I execute PHP code from the command line?
(6 answers)
Closed 2 years ago.
When I run PHP in my console (any cli application) and I sending a command like below, it not returned anything!
echo 'Hi!';
Is there any way to run PHP commands directly in console or just we can run a .php file?
Note: My environment variables and path is OK.
You may use PHP's interactive shell
php -a
echo 'Hi!';
This question already has answers here:
Php exec command not working on Windows, works on command line
(3 answers)
Closed 6 years ago.
When I execute the code below in command line it runs fine:
C:\Users\Shraddha\book ticket\ex1 scrapy crawl bookmyshow
However it doesn't execute in PHP using exec():
exec("C:\Users\Shraddha\book ticket\ex1 scrapy crawl bookmyshow");
You need to escape the blank characters in the path, otherwise they are interpreted as separator between multiple arguments. Also it is much safer to use the forward slash as folder separator as it is used in unixoid systems and the internet in general:
exec("C:/Users/Shraddha/book\ ticket/ex1\ scrapy\ crawl\ bookmyshow");
If you insist on MS-Windows style separators, then you have to escape them too:
exec("C:\\Users\\Shraddha\\book\ ticket\\ex1\ scrapy\ crawl\ bookmyshow");
Also you may prefer to use shell_exec() here to have a well defined and initialized environment for your command to be executed in.
This question already has answers here:
Running PHP script from the command line
(3 answers)
Closed 8 years ago.
I want to run php files using command prompt.For this I set the system variable's path variable(C:\wamp\bin\php\php5.4.16).
After set the path I restart the system and I m trying to run the php file.
I typed
php test.php
But its says
Could not open input file
Run:
pear
it will set %PHP_PEAR_PHP_BIN% for you.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
php shell_exec() vs exec()
How do I run a linux command from a PHP script? I'm running Linux Debian and PHP5. I want to be able to issue a wget command to the console.
An example of what I'm looking for is something like this:
phpFunction ("wget http://www.example.com/image.jpg /folder");
echo "done";
Also would I be able to echo the output of that function?
Use exec to run any command. Be careful not to exec any user input though, as it can severely compromise your server.
Also, note that most shared servers block off the exec function so you won't be able to use it.
Finally, as a shorthand, you can wrap the command you want to exec in backticks.
You can do what you want with the following code :
system(command);
See http://php.net/system
You can execute linux commands within a php script - all you have to do is put the command line in brackits (`).
And also concentrate on exec() , this and shell_exec() ..
you can use
exec
shell_exec
http://php.net/manual/en/function.shell-exec.php
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Call Python From PHP And Get Return Code
probably a very stupid question
I have a python module lets say hi.py which have the following
print "hi"
now I want to execute this file from php
<?php
#code here
?>
So how do I call that python file from php.
Thanks
Use the exec function to invoke Python.
Example:
$output = array();
exec("python hi.py", $output);
var_dump( $output);
There are other commands for executing commands on the machine PHP is running on, see the docs.
you can call php exec function and call
python -c "print 'hi'"
or if you have larger module you can use
-m mod : run library module as a script (terminates option list)
so in the end I'd use
exec("python -m hi");
and don't forget to configure PYTHON_PATH on your server if needed
be careful doing this kind of stuff