“Could not open input file” error even when WP-CLI is in the path

I finally managed to scrape together enough information from disparate sources to figure out how to fix this, because – as I’m increasingly finding with anything related to WordPress development – the documentation is so woefully inadequate.

The fact that it took so much research and hacking together on my part just to get an official command-line utility working on a platform that it claims to support is ridiculous, and my estimation of the WordPress project and the Automattic team has dropped massively over the last few weeks for such reasons.

What follows in this answer adapts information from aefxx’s answer here and leymannx’s answer to this question.

As far I can tell, the issue here is that php.exe – the PHP binary included with XAMPP, WAMP and similar local servers – is a Windows binary that only understands paths in Windows format. The solution, as coded by aefxx in his answer, is to use a wrapper script that checks for Unix-style paths passed to the PHP binary and converts them into Windows paths that it can understand.

Note that because this solution is implemented as a wrapper to the PHP binary itself, it should work to solve this issue for any PHP program running under Cygwin, not just WP-CLI.

How to get WP-CLI working with Cygwin

Remember to replace any paths below with your own.

Once you’ve downloaded the wp-cli.phar file and made it executable as detailed in the documentation, move it to your server’s PHP directory while renaming it to wp:

mv /cygdrive/b/Users/User/Desktop/XAMPP/php/wp

Inside the PHP directory, run the following:

touch php
chmod +x ./php

This creates a file called php inside of the PHP directory and makes it executable. This file will function as the wrapper script. Open the file in a text editor and paste the following into it, replacing the path to the PHP executable with your own:

#!/bin/bash

php="/cygdrive/b/Users/User/Desktop/XAMPP/php/php.exe"

for ((n=1; n <= $#; n++)); do
    if [ -e "${!n}" ]; then
        # Converts Unix style paths to Windows equivalents
        path="$(cygpath --mixed ${!n} | xargs)"

        case 1 in
            $(( n == 1 )) )
                set -- "$path" "${@:$(($n+1))}";;
            $(( n < $# )) )
                set -- "${@:1:$((n-1))}" "$path" ${@:$((n+1)):$#};;
            *)
                set -- "${@:1:$(($#-1))}" "$path";;
        esac
    fi
done

"$php" "$@"

Run cygstart ~/.bash_profile to open the .bash_profile file, and add the following to the end of it to add XAMPP’s PHP directory to the PATH environment variable:

export PATH="/cygdrive/b/Users/User/Desktop/XAMPP/php:$PATH"

Finally, run source ~/.bash_profile to load the new contents of the .bash_profile file.

Finally, run wp to confirm that WP-CLI is now working.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)