Creating batch file launching .phar with alias

I’m currently experimenting with WP-CLI (http://wp-cli.org) – I have finally managed to get it to run on my basic command line by downloading/moving it to a PATH variable directory (i.e C:xamppphp) and then updating my PATHSPEC to include .PHAR.

I have renamed the original file from wp-cli.phar to wp.phar in order to be able to reference it as wp in my cmd.exe.

Read More

Prior to this method I installed wp-cli using CURL and chmod in my Git Bash installation then renaming the file to wp (without an extension) and adding the path containing file to the PATH variable. This caused the .PHAR file to work in Git Bash but not to work on the command line.

MY ISSUE:

Whenever I try to use my wp.phar in the native CLI I get a php error report – it does recognise the command and does show a list of suggestions (which is usually given when syntax is incomplete or incorrect).

command line screenshot showing my output

How do I even start to figure this out?

1 – I’ve attempted to look for a git batch file in my Git Bash directory to see if I can find a dependency I’m missing but no dice.

2 – My Git Bash is now not recognizing the wp command and I now need to refer to wp.pharand then add any sub-commands/arguments after. However using the Git Bash CLI wp.phar doesn’t cause errors

Related posts

Leave a Reply

1 comment

  1. After a few months I found a solution.

    1. Make sure that your PHP root folder path and the folder path containing your phar files are added to the Windows PATH Environment Variable (to allow us to just use the filename to refer to them).
    2. CMD Line Options (Run as Administrator):

      • assoc .php=phpfile and assoc .phar=pharfile

    How to associate .php files on windows with a global variable name

    • Next is adding the program that opens this file. Adding an ftype command allows us to open .php/.phar files without using the php.

      ftype pharfile=php.exe %1 %* (The %1 is a placeholder for the file called and %* refers to any other arguments that many be input).

    How to get php to open all files with .php by default

    FINALLY

    The key issue was getting the .phar scripts to execute in the command line as windows ends up trying to open these files in it’s Open With Dialog

    Open with Dialog Issue which occurs when trying to open .phar file without GUI application.

    So what I did was wrap my .phar in a batch file with this command (in the same folder as the phar

    echo php "%~dp0wp-cli.phar" %* > [name of file].cmd

    I then run this file as [name of file] with any arguments and it works as usual.