I have .phar file and i want to run it from anywhere with this command.
php file.phar --options
where file.phar is in C:\my-php-cli\file
That is not possible. For example, putting file.phar
to C:\Windows\System32
and calling php file.phar --options
from another directory like C:\Temp
will produce
Could not open input file: file.phar
You have to create a small batch file next to your *.phar, e.g., run-file.bat
with this contents:
@ECHO OFF
php %~dp0file.phar %*
Then, calling run-file
will execute your file.phar
.
For Windows 10 I found that you need a your-file.cmd to run the .phar file.
I was trying to get php-cs-fixer running so in my PHP directory i had the following:
PHP\
phpFixer\
php-cs-fixer.phar
php-cs-fixer.cmd
Contents of php-cs-fixer.cmd:
@php "%~dp0php-cs-fixer.phar" %*
verified it works by entering this in command line:
php-cs-fixer --version
PHP CS Fixer 2.14.0 Sunrise by Fabien Potencier and Dariusz Ruminski (b788ea0)
Hope that helps
You would need to add the folder containing file.phar to your path variable.
See this link for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With