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']);
Related
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
I have a small script I tested on the command line using php test.php.
test.php
<?php
exec('ps -acux | grep test', $testvar);
print_r($testvar);
?>
This works fine. I am able to run the script and get the desired result. However, when I add the code to a file being run by my PHP server, the result is empty.
My OS is FreeBSD. Looking at the man page for ps the only restriction I see is on the -a option. It states:
If the security.bsd.see_other_uids sysctl is set to zero, this option
is honored only if the UID of the user is 0.
My security.bsd.see_other_uids is set to 1.
$ sysctl security.bsd.see_other_uids
security.bsd.see_other_uids: 1
The only thing I can think of is that the command is being run by my user when I run it via the command line whereas when run by PHP, it's being run by www. I'm not seeing anything in the manual of ps that indicates www shouldn't be able to run the command.
As per the comments you need to redirect stderr to stdout. This is achieved by 2>&1 to the end of your command. So an example of the PHP exec() is as follows:
exec('ps -acux | grep test 2>&1', $testvar);
This allows you to see potential errors. In my case there was no error and likely a bug of some sorts. However this is useful in all cases where you execute a command. If any error were to occur you can retrieve it to see what is happening with your command.
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"
I am starting a PHP daemon from command line in env A successfully. Yet, in env B, it stops right after being started. Same code. No error message.
I was wondering how I could set the maximum debug/log level output when launching the daemon. Is there a specific parameter I can pass? I am willing to collect more information than nothing.
You can enable reporting of all messages like this:
$ php -d error_log= -d log_errors=1 -d error_reporting=E_ALL e.php
HAI
file e.php contents
<?php
error_log('HAI');
You should also inspect the exit code of the daemon as that may be a standard unix exit code that would give you some clue.
php e.php ; echo $?
Refs
http://www.php.net/manual/en/errorfunc.configuration.php
I tried to generate LLVM intermediate code by calling
llvm-gcc -emit-llvm -I/mypath/ -c main.c -o main.o
It works perfectly without any warnings or errors if I manually type this command in the terminal.
However I have built a website that can automate this process by calling exec function in PHP like below.
exec("llvm-gcc -emit-llvm -I/mypath/ -c main.c -o main.o",$msg,$ret);
It will still generate .o file with a warning. The warning says that
Potential incompatible plugin version. GCC: 4.5.3. Expected: 4.5.4
Defines 'dragonegg_disable_version_check' as env variable to remove this warning.
Please note that unexpected errors might occur.
The php command will still return 0, which is successful. However when I run the generated .o file, it will throw invalid bitcode signature error.
The server is running ubuntu and Apache. My llvm-gcc version is 2.9 which uses 4.2.1 gcc.
Any help will do. Thank you!
The best thing would be to update the GCC to 4.5.4. But if you just want to hide the warning, simply define dragonegg_disable_version_check.
$command = 'dragonegg_disable_version_check=1'
. ' llvm-gcc -emit-llvm -I/mypath/'
. ' -c main.c -o main.o';
exec($command,$msg,$ret);
For the invalid bit code signature error -- see this questions.