PHP command line prompt "Could not open input file" solution

I used the command line to run the php code under Windows, and I thought it would produce results directly, but the following error was reported:

Could not open input file: echo`ipconfig`;

 

 

Solution

The reason is actually very simple. The way to use the PHP command line is incorrect. The correct way to use the PHP command line is as follows:

 

The first method: let PHP run the specified file

F:\phpStudy>php my_script.php

F:\phpStudy>php -f my_script.php

Both of the above methods (with or without the -f parameter) can run the given my_script.php file. Any file can be selected to run. The specified PHP scripts do not have to have a .php extension, they can have any file name and extension.

 

Second method: Run PHP code directly on the command line

F:\phpStudy>php -r echo`ipconfig`;

When using this method, please note the substitution of shell variables and the use of quotes.

 

Notice:

If you have not added php.exe to the environment variable, it is recommended that you directly enter the php installation directory and then execute the command. The specific operation example under Windows is as follows:

C:\Users\fujie>f:

F:\>cd F:\phpStudy\php\php-5.5.38

F:\phpStudy\php\php-5.5.38>php -r echo('123');

Guess you like

Origin blog.csdn.net/weixin_39691535/article/details/101012516