How can I run php commands directly in console? [duplicate] - php

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!';

Related

How to specify PHP static function argument from terminal [duplicate]

This question already has answers here:
Pass a variable to a PHP script running from the command line
(14 answers)
Closed 6 years ago.
I have a script, which executes by Example::main("file.csv");.
I want to run the script from the terminal, but how can I achieve, so I don't define the argument in the script, but in the terminal, like php Example.php file.csv?
Thanks!
Example::main($argv[1]); is the solution.

PHP CMD error : Could not open input file [duplicate]

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.

How can I run a linux command from a PHP script [duplicate]

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

php exec in background not working [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Call another PHP script and return control to user before the other script completes
Hello,
I'm executing this command in php:
exec('php /path/to/script.php one_argument_passed &");
But it's not executing it in the background. Is there a setting or something in php I need to do to make this work?
Maybe you have a permissions problem.

Python and executing php files? [duplicate]

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().

Categories