cmd 运行php文件详解,[记录]在cmd内运行ThinkPHP5目录内的php文件

众所周知,cmd运行php单文件的命令是

E:\test>php test.php

但是自己写数据库连接或者一些其他东西就很繁琐

直接用tp就很方便

上面的命令是不适用于执行ThinkPHP内php文件的

那么在cmd怎么执行ThinkPHP内的php文件呢?

准备工作:

首先在 app > command.php 内添加如下代码

return [

'app\index\command\Test',

];

二.在app > index 目录下创建名为 command 的文件夹, 再创建一个名为 Test.php 的文件

a1d3a97b1852878c1bbede387cd18660.png

在 Test.php 内写入如下代码

namespace app\index\command;

use think\console\Command;

use think\console\Input;

use think\console\Output;

class Test extends Command

{

protected function configure()

{

$this->setName('Test')->setDescription('Here is the remark ');

}

protected function execute(Input $input, Output $output)

{

$output->writeln("TestCommand");

// 在这里写你要执行的业务代码

}

}

以上我们的准备工作就做完了~

打开小黑框:

然后我们可以打开 cmd 运行一下

注意:cmd目录切换到tp5的根目录就可以

输入:

E:\test>php think Test

输出:

TestCommand

-End-

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值