Windows 8:.phar文件,您想如何打开

Joh*_*Doe 10 php cmd wamp composer-php

我正在尝试用wamp在windows上运行composer.我使用cmd提示符安装了composer,现在我正在尝试为SDK运行"composer update".但是,当我输入"composer.phar update"时,windows会询问我想用什么应用来运行这个程序.我想要命令提示符来处理它!如何在没有这个"什么应用程序"窗口的情况下通过cmd运行它?

Joh*_*hni 15

您必须将php.exe设置为phar文件的默认应用程序.


Ale*_*vić 5

.phar 代表 PHP 存档

通常.phars 带有一些参数,因此它们旨在从命令提示符运行。Linux/BSD/OS X shell 或 Windows 命令提示符。

Linux.phar用例场景假设.phars 被复制到某个 /bin 并重命名为没有 .phar 扩展名,因此您可以像使用任何其他 linux 命令一样使用 php 存档。所以我建议使用以下方法在 Windows 上做同样的事情:

  1. 将所有.phar文件放在一个目录中,例如C:\php\phars
  2. 添加C:\php\phars到系统环境变量(右键单击 my Computer -> Properties -> Advanced System Settings -> Environment variables
  3. 启动提升的命令提示符(在开始菜单中找到命令提示符,然后右键单击并选择Run as Administrator
  4. 键入以下命令,将路径替换为C:\phpdev\php\php542\php.exePHP 可执行文件的完整路径:
ftype PHARFile=C:\phpdev\php\php542\php.exe "%1" %*
assoc .phar=PHARFile
set PATHEXT=%PATHEXT%;.PHAR
Run Code Online (Sandbox Code Playgroud)

下次您应该能够运行 Windows 控制台(键盘Win+R和类型cmd.exe)并输入您.phar喜欢apigen.phar的任何命令,然后输入任何命令,它就可以工作了

C:\Users\acosonic>apigen.phar help
Usage:
...

Arguments:
 command        The command to execute
 command_name   The command name (default: "help")

Options:
 --xml          To output help as XML
 --format       To output help in other formats (default: "txt")
 --raw          To output raw command help
 --help (-h)    Display this help message.
 --quiet (-q)   Do not output any message.
 --version (-V) Display this application version.

Help:
 The help command displays help for a given command:

   php C:\phpdev\phars\apigen.phar help list

 You can also output the help in other formats by using the --format option:

   php C:\phpdev\phars\apigen.phar help --format=xml list

 To display the list of available commands, please use the list command.

C:\Users\acosonic>
Run Code Online (Sandbox Code Playgroud)

因此,通过这种方式,您可以.phar在需要工作的目录中运行存档,例如在C:\myproject\controller不指定完整路径的情况下生成文档,.phar就像在不将其添加到 Windows 路径的情况下运行一样。

解释步骤 4 中的命令做了什么:

  1. 创建映射 HKCR.phar ?HKCR\PHAR 文件
  2. 创建 HKCR\PHARFile\shell\open\command = 'php.exe "%1" %*' [REG_EXPAND_SZ]
  3. 扩展 HKCU\Environment\PATHEXT = '%PATHEXT%;.PHAR' [REG_EXPAND_SZ]

*.phar被视为二进制/脚本,*.phar只要*.phar文件位于%PATH%.