Display Laravel artisan command output (command called from another command) - laravel

I am writing a console command. This command also calls another command.
Basically say: php artisan command:one. So inside command one, I call php artisan command:two.
They both have interactions ($this->info()) stating the progress or state of the current operations. But when I run php artisan command:one I can't see this displayed info from php artisan command:two, though php artisan command:two has its own output info and progress state.
How do I ensure to see the progress and states from php artisan command:two which is called in php artisan command:one?

Using Artisan::call() doesn't redirect called command's output to original command's output.
To call another Artisan command and save its output you should use $this->call() from your command.

Related

How to prepend function before calling by line a command by Artisan?

I have a doubt, I know that to call only laravel commands I have to use the command Artisan::call('command name') but how can I do it if I want to execute the following task
Artisan::call('cat archive | php artisan project:method'); //NOT WORK
cat name_file | php artisan project:method
For example I want to execute the command
CAT /tmp/archive.eml | php artisan command:name_method
Since what I want to do is to read files with cat that are in another directory through a foreach and enter the command that manipulates the data of those files.

How will I run queue listener of Laravel 5.2 in background?

In my project I am using database queue and executing this queue by using command
php artisan queue:listen
in composer and it is working. But in my windows server, there are many projects that using queues so many windows of composer are open. It is quite inconvenient. Is this possible to run this command in background without composer window open?
YOu can use the command but it will work only until you logout or restart
nohup php artisan queue:work --daemon &
The trailing ampersand (&) causes process start in the background, so you can continue to use the shell and do not have to wait until the script is finished.
See nohup
nohup - run a command immune to hangups, with output to a non-tty
This will output information to a file entitled nohup.out in the directory where you run the command. If you have no interest in the output you can redirect stdout and stderr to /dev/null, or similarly you could output it into your normal laravel log. For example
nohup php artisan queue:work --daemon > /dev/null 2>&1 &
nohup php artisan queue:work --daemon > app/storage/logs/laravel.log &
But you should also use something like Supervisord to ensure that the service remains running and is restarted after crashes/failures.
Running queue:listen with supervisord
supervisord is a *nix utility to monitor and control processes below is a portion of /etc/supervisord.conf that works well.
Portion of supervisord.conf for queue:listen
[program:l5beauty-queue-listen]
command=php /PATH/TO/l5beauty/artisan queue:listen
user=NONROOT-USER
process_name=%(program_name)s_%(process_num)d
directory=/PATH/TO/l5beauty
stdout_logfile=/PATH/TO/l5beauty/storage/logs/supervisord.log
redirect_stderr=true
numprocs=1
You’ll need to replace the /PATH/TO/ to match your local install. Likewise, the user setting will be unique to your installation.

Print log to terminal running artisan serve

I am trying to debug my application and I had few log statements using Log facade. For now, I run the application using artisan serve and it will write the log message to the log file and to get a real time log message I run.
tail -f laravel.log
Is there any way I can directly print the log message to the same console/terminal that is running php artisan serve?
You can do this using following. This works anywhere..
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$output->writeln("<info>Error message</info>");
This will print the message in terminal / console that is running php artisan serve
tail -f storage/logs/laravel.log & php artisan serve
Based on #aquasmit answer:
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$output->writeln("<info>Info message</info>");
Note the added \ before Symfony.
The standard "error_log" PHP function does what you want.

Bash run previous command with all arguments without last

I often do something like this:
php artisan route:list
php artisan migrate
php artisan db:seed
Only artisan command name is changed. I know how to get all parameters of previous command except last: !:1- (in my case it gives me artisan). But maybe exist shortcut that gives me command name with all arguments except last (in my case php artisan)? I know I can use alias a="php artisan" for such purpose, but general shortcut for any command will be very useful.
The same trick applies, just change 1 to 0
!:0-
What about a function? I called it rms for route; migrate; seed
rms () { php "$1" "route:list"; php "$1" migrate; php "$1" "db:seed"; }

Use phpmd as php artisan phpmd

Hello, I am working on app in which i need to use phpmd as php artisan phpmd(i ). means make phpmd as local command and use in project.requirement is when i clone the project no additional things should be required and one can freely run `php artisan phpmd` command.which work same as `phpmd`
command will be like php artisan phpmd <file> <ruleset>
I guess you're already have your Artisan command ready and working. Then best approach will be creating .bat script for Windows and .sh script for Unix systems and placing it in Laravel project's root directory.
For example, phpmd.bat file can look like that:
php artisan phpmd %1 %2
When you'll clone the project, you can just run phpmd someFile someRuleset from Laravel project directory and it should work exactly as php artisan phpmd someFile someRuleset command.
For Ubuntu, Mac and other Unix OS .sh file will look similar:
#!/bin/sh
php artisan phpmd $1 $2

Resources