问题描述
我经营工匠:
php artisan down --message "Going down for maintenance" --retry=60
[更新]或像@Remul建议的那样运行它:
[UPDATE] OR run it like @Remul suggested:
php artisan down --message="Going down for maintenance" --retry=60
然后两者都给了我错误:
then both gives me the error:
[Symfony\Component\Console\Exception\RuntimeException]
Too many arguments, expected arguments "command".
如果运行命令没有这样的空格:
If run command with no spaces like this:
php artisan down --message "Going_down_for_maintenance" --retry=60
没有错误发生
推荐答案
我正在使用php 7.0.14
I am using php 7.0.14
我想通了:
问题实际上是php从命令行获取参数的方式在vendor/symfony/console/Input/ArgvInput.php中,我可以理解php会得到如下所示的错误:
Problem is actually how php is getting arguments from command lineIn vendor/symfony/console/Input/ArgvInput.php I could understand that php gets argfuments like this:
0 => "artisan"
1 => "down"
2 => "--message=Going"
3 => "down"
4 => "for"
5 => "maintenance"
6 => "--retry=60"
因此,甚至要确保我使用以下内容制作了自己的脚本:
So to even make sure I made a script of my own with this content:
<?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的计算机上运行它,并查看我的结果:
I run it in other machine with a different version of PHP and look at my results:
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的解析是完全不同的,人们会忽略双引号作为字符串定界符,而后面的则不会这样做
Looks like in php 7.0 and 7.1 argv parsing is quite different, one ignores the double quotes as string delimiter and the later don't
这篇关于Laravel工匠使用带有空格的消息参数给出了太多的参数,期望的参数"command"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!