Laravel artisan down with message parameter with spaces 给出 Too many arguments, expected arguments "command"

Laravel artisan down with message parameter with spaces gives Too many arguments, expected arguments "command"

我运行 artisan:

php artisan down --message "Going down for maintenance" --retry=60

[更新] 或 运行 就像@Remul 建议的那样:

php artisan down --message="Going down for maintenance" --retry=60

然后都给我错误:

[Symfony\Component\Console\Exception\RuntimeException]
 Too many arguments, expected arguments "command".

如果 运行 命令没有这样的空格:

php artisan down --message "Going_down_for_maintenance" --retry=60

没有错误发生

此消息在名为 storage/framework/down 的 JSON 格式文件中可用,该文件由 php artisan down 命令生成。

您可以打开该文件并进行修改。

祝你好运

我正在使用 php 7.0.14

我想通了:

问题实际上是 php 如何从命令行获取参数 在 vendor/symfony/console/Input/ArgvInput.php 中,我可以理解 php 得到这样的参数:

0 => "artisan"
  1 => "down"
  2 => "--message=Going"
  3 => "down"
  4 => "for"
  5 => "maintenance"
  6 => "--retry=60"

因此,为了确保我用以下内容制作了自己的脚本:

<?php

var_dump($argv);

而我运行它:

php -v;php test_argv.php "parm with space" other_parameter

输出为:

PHP 7.0.14 (cli) (built: Jan 30 2017 15:45:33) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
array(5) {
  [0]=>
  string(13) "test_argv.php"
  [1]=>
  string(4) "parm"
  [2]=>
  string(4) "with"
  [3]=>
  string(5) "space"
  [4]=>
  string(15) "other_parameter"
}

我运行在其他机器上使用不同版本的PHP,看看我的结果:

PHP 7.1.5 (cli) (built: Sep 19 2017 10:48:01) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Xdebug v2.5.4, Copyright (c) 2002-2017, by Derick Rethans
array(3) {
  [0] =>
  string(13) "test_argv.php"
  [1] =>
  string(15) "parm with space"
  [2] =>
  string(15) "other_parameter"
}

看起来 php 7.0 和 7.1 argv 解析完全不同,一个忽略双引号作为字符串分隔符,而后者则不

这是一个不相关的问题,但这是 Google 派我来的地方,因为我犯了这个错误...所以..

获得的其他常见原因:

Too many arguments, expected arguments "command".

当 artisan 脚本需要一个选项时,您是否正在提供一个参数。所以你需要改变

./artisan yourcommand:yoursubcommand some_kind_of_input

./artisan yourcommand:yoursubcommand --an_option=some_kind_of_input

该错误通常意味着 artisan 不希望此命令有任何类型的附加参数...

我有同样的问题,只需要使用反斜杠转义消息:

php artisan down --message "Going\ down\ for\ maintenance" --retry=60