You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aquaculture/app/Console/Commands/BaseCommand.php

55 lines
1.3 KiB

<?php
namespace App\Console\Commands; // 定义命名空间
use Illuminate\Console\Command; // 引入 Laravel 命令基类
/**
* 基础控制台命令类
*
* 该类提供了一个基础命令实现,包含执行 shell 命令并打印输出的功能。
*/
class BaseCommand extends Command
{
/**
* 控制台命令的名称和签名
*
* @var string
*/
protected $signature = 'moon:base'; // 定义命令的名称和签名
/**
* 控制台命令的描述
*
* @var string
*/
protected $description = 'don`t use'; // 描述该命令的用途,当前设置为“不建议使用”
/**
* 创建一个新的命令实例.
*
* @return void
*/
public function __construct()
{
parent::__construct(); // 调用父类构造函数
}
/**
* 执行 shell 命令并打印输出
*
* @param string $command 要执行的 shell 命令
* @return void
*/
public function execShellWithPrint($command)
{
$this->info('----------'); // 打印分隔线
$this->info($command); // 打印要执行的命令
// 执行 shell 命令并获取输出
$output = shell_exec($command);
$this->info($output); // 打印命令的输出结果
}
}