Too many arguments, expected arguments "command" - php

I'm trying to run a custom command through the terminal, but keep getting the error: Too many arguments, expected arguments "command".
When searching for similar issues all i've been able to find was people using the scheduler, and nothing about calling the command from terminal.
The signature for the command i'm trying to run is:
class MigrateSiteMysiteCommand extends Command
{
protected $signature = 'migrate:site:mysite.dk {--from=} {--to=}';
...
And then i use php artisan help migrate:site:mysite.dk i get this:
Usage:
migrate:site:mysite.dk [options]
Options:
--from[=FROM]
--to[=TO]
-h,--help Display this help message
-q,--quiet Do not output any message
-V,--version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n,--no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose
output and 3 for debug
I've tried running the command in different ways formatting the arguments, but get the same error either way:
php artisan migrate:site:mysite.dk --from=2019-02-27 16:22:10 --to=2019-02-28 23:59:59
php artisan migrate:site:mysite.dk --from='2019-02-27 16:22:10' --to='2019-02-28 23:59:59'
php artisan migrate:site:mysite.dk --from '2019-02-27 16:22:10' --to '2019-02-28 23:59:59'
php artisan migrate:site:mysite.dk --from 2019-02-27 16:22:10 --to 2019-02-28 23:59:59
Any suggestions to what i'm missing, or messing up in the command ?
I've been able to run other commands, which didn't need any arguments passed.

The parameters had to be wrapped in " instead of ', so the working command looks like this:
php artisan migrate:site:mysite.dk --from="2019-02-27 16:22:10" --to="2019-02-28 23:59:59"

Related

Laravel Crontab + Shell Exec

I have a Laravel App with Short Schedule package installed and a crontab to execute it.
Inside the executed method I have a SHELL_EXEC function with some code inside it.
The problem is that when the code runs automatically using the cron, the SHELL EXEC doesn't work. The output is null.
When I run the method directly using php artisan or by simply running the schedule using php artisan manually, it works.
To have a clear vision of what's going on:
Inside the crontab -e I have the following
* * * * * php /var/www/html/project/artisan short-schedule:run --lifetime=60
The cron executes this method which has the following code:
$shell_command = '/home/paul/elrondsdk/erdpy --verbose tx new --receiver xxxx --send --pem asdfa.pem --gas-limit 300 --nonce 12';
$output = shell_exec($shell_command);
Log::info('output', [$output]);
If it runs automatically using the cron, the $output is NULL.
If I run the command manually, I get a proper output.
Initially I thought I need to specify the exact path in the shell exec because cron doesn't not PATH. Unfortunately did not solve my problem.
Thanks!
I tried to run the command manually or to run php artisan schedule:run and wait and it worked!
It doesn't work ONLY when its runs by the cron.

/usr/bin/less: unrecognized option: X laravel docker error

i am using laravel on docker . i run my project when i exec into container and use
php artisan tinker
no matter what command i run i receive this error :
bash-5.1$ php artisan tinker
Psy Shell v0.11.8 (PHP 8.0.14 — cli) by Justin Hileman
>>> App\Models\User::where('id',12)->first()->createToken('testToken');
/usr/bin/less: unrecognized option: X
BusyBox v1.34.1 (2021-11-23 00:57:35 UTC) multi-call binary.
Usage: less [-EFIMmNSRh~] [FILE]...
View FILE (or stdin) one screenful at a time
-E Quit once the end of a file is reached
-F Quit if entire file fits on first screen
-I Ignore case in all searches
-M,-m Display status line with line numbers
and percentage through the file
-N Prefix line number to each line
-S Truncate long lines
-R Remove color escape codes in input
-~ Suppress ~s displayed past EOF
RuntimeException with message 'Error closing output stream'
any idea what can be wrong here ?
Busybox contains cutdown versions of many Unix/Linux utilities, including less. Either remove it and install the less package, as well as the other utilities it mimics, or hack artisan and remove the -X switch against /usr/bin/less. All the -X switch does is sort alphabetically by entry extension
Ugh just spent a ton of time messing with this one myself.
The root cause of this issue is the upgrading of the psypsh shell package that tinker users.
You can see in the release notes here https://github.com/bobthecow/psysh/releases/tag/v0.11.3
There are a few ways around this, as mentioned above, you can just install the less package using apk or apt-get.
You can also set the cli.pager property in your php.ini file to explicitly call less without the -X switch.
More info here: https://github.com/bobthecow/psysh/issues/717

Unable to run a Laravel Artisan command with parameters using Symfony process [duplicate]

This question already has an answer here:
symfony 4 process running a command, not running
(1 answer)
Closed 1 year ago.
I'm trying to start a process with Symfony in my Laravel app on my shared hosting server that will call an Artisan command with parameters like so:
$process = new Process(['/usr/local/bin/php', base_path('artisan'), 'queue:work --stop-when-empty']);
$process->setTimeout(null);
$process->start();
This does not work as I get:
ERROR: Command "queue:work --stop-when-empty" is not defined.
Did you mean one of these?
queue:batches-table
queue:clear
queue:failed
queue:failed-table
queue:flush
queue:forget
queue:listen
queue:monitor
queue:prune-batches
queue:prune-failed
queue:restart
queue:retry
queue:retry-batch
queue:table
queue:work {"exception":"[object] (Symfony\\Component\\Console\\Exception\\CommandNotFoundException(code: 0): Command \"queue:work --stop-when-empty\" is not defined.
The problem is with the parameter --stop-when-empty as the command runs succesfully wthout it. How can I pass this parameter to the command ?
The process adds quotes around each array value that you pass in. Right now, it's attempting to run
"exec '/usr/local/bin/php' '/your/path/to/artisan' 'queue:work --stop-when-empty'"
So by adding quotes around the whole string, it's treating 'queue:work --stop-when-empty' as a single command, instead of a command and option. Separate out the command so that it will quote it properly
$process = new Process(['/usr/local/bin/php', base_path('artisan'), 'queue:work', '--stop-when-empty']);

Why is $this->argument() Showing the Name and the Value?

In Laravel, I am making a console command. Per the docs, you should be able to get the value of the argument using $this->argument():
$userId = $this->argument('user');
I have an argument that is an integer 1. However, $this->argument('some_name') is returning a string such as some_name=1, instead of simply 1
Is there a setting or something that I missed?
Arguments don't get named, unlike options. For example:
$ php artisan command argument1 argument2 argument3
$ php artisan command --option1=foo --option2=bar
So, I'd either change the definition of your argument to an option so that you can run:
$ php artisan command --some_name=1
Or, you can keep using this as an argument and run:
$ php artisan command 1
Note: artisan and command in the above examples are arguments of the php executable.

Show help text when command encounters error

I have a working command. I want to add some options to it. None of these options are technically required, but at least and at most 1 of them needs to be supplied for any single invocation of the command. I have the options set up and can detect successfully these circumstances.
However, I wish to show the help dialog for the command whenever the check fails. If my command is my:command, I want the output of running $ php artisan my:command -h to display after my error message.
I have tried doing this:
$this->error('my error message');
// Causes infinite failness since it is calling the command but not passing
// options (or ignoring it), thus hitting the same error condition
$this->call('my:command', ['-h' => true]);
// Causes.. nothing. No error, no blank line, I just see my error message
Artisan::call('help', ['command_name' => 'my:command', 'format' => 'txt']);
// Both of these also cause nothing to be displayed. They are from:
// Symfony\Component\Console\Command\Command
echo $this->getHelp();
echo $this->getProcessedHelp();
Is there a way to get the same formatted help text of a command or trigger the help message to display when an error like this is encountered?
Update
The default output for a command when running $ php artisan help my:command is something like this:
Usage:
my:command [options] [--] [<argument>]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
I want to output this after my error message.
To show help message after your error add this after your error message line
$this->call('help', ['command_name' => 'test:mycommand', 'format' => 'raw']);

Categories