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

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.

Related

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

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

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.

Test if a cron is executed only by the server [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
In php, how to detect the execution is from CLI mode or through browser?
How to test if a cron is executed only by the server
Thanks
Cron will never put anything on the display unless you use something like 'wall' in your cron script.
Are you redirecting your output to a log file or anything?
What you can do is to add a line at the bottom of the script you are executing in the cron; that does something like:
date +"%D %r `echo Cron completed`" >> /tmp/cron_job.log
Then you could check
cat /tmp/cron_job.log
and it would tell you when it finished.

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