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

允我心安 提交于 2020-03-22 09:22:49

问题


I run the artisan:

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

[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

No error occurs


回答1:


I am using php 7.0.14

I figured out:

Problem is actually how php is getting arguments from command line In 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);

And I run it:

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

The output was:

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"
}

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"
}

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




回答2:


This message is available in a JSON formatted file named storage/framework/down generated by php artisan down command.

You can open that file and modify it.

Goodluck




回答3:


This is an unrelated problem, but this was the place where Google sent me as I made this mistake... soo..

The other common reason to get:

Too many arguments, expected arguments "command".

Is that you are providing an argument, when the artisan script is expecting an option. So you need to change

./artisan yourcommand:yoursubcommand some_kind_of_input

to

./artisan yourcommand:yoursubcommand --an_option=some_kind_of_input

The error just generally means that artisan was not expecting an additional argument of any kind to this command...



来源:https://stackoverflow.com/questions/53191654/laravel-artisan-down-with-message-parameter-with-spaces-gives-too-many-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!