WP-CLI在Windows命令提示符中可以运行,但无法在Git Bash中运行。

9
我已安装了wp-cli(WordPress命令行接口),并使用Git-bash创建了相关PATH变量。
现在我可以在Windows CMD中输入“wp”并起作用,但是Git-bash无法识别该命令。
我需要做什么才能使Git-bash正常工作,为什么它不能直接使用?
1个回答

17

我遇到了同样的问题。例如命令"wp cli version"在cmd中运行正常,但在cygwin中不行。

请查看以下教程:https://deluxeblogtips.com/install-wp-cli-windows/

如果您使用的是cygwin,则需要创建另一个wp文件(不带.bat扩展名)。只需将其命名为wp,并使用以下内容:

#!/usr/bin/env sh

dir=$(d=${0%[/\\]*}; cd "$d"; pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
    # Cygwin paths start with /cygdrive/ which will break windows PHP,
    # so we need to translate the dir path to windows format. However
    # we could be using cygwin PHP which does not require this, so we
    # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
    if [[ $(which php) == /cygdrive/* ]]; then
        dir=$(cygpath -m $dir);
    fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/wp-cli.phar" "$@"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接