如何在Windows的交互式CLI中运行php [英] How to run php in interactive CLI in Windows
问题描述
我想在命令行界面中运行PHP,我想在每行写完之后获取输出。
I would like to run PHP in a command-line-interface and I would like to get output after every line I write.
我在其中有php.exe我的PATH环境变量。我使用php -r echo'Hello world'或
I have php.exe in my PATH environment variable. I use php -r "echo 'Hello world'" or
php -a
Interactive mode enabled
<?php
echo "hello world"
?>
^Z
但是我想要一个真正的php shell,它在每个命令后都会做出反应。我在Python中使用了类似的东西。这在PHP中可行吗?您可以推荐一个具有此功能的程序。
But I want a real php shell, which reacts after every command. I have used something similar in Python. Is this possible in PHP? You can recommend a program that has this feature.
推荐答案
有关强大的交互式PHP CLI,建议您看一下< a href = http://psysh.org/ rel = nofollow> PsySH 。安装非常简单,只需运行一个命令即可:
For a powerful interactive PHP CLI, I suggest you take a look at PsySH. It's very easy to install, you just have to run one command:
composer g require psy/psysh:@stable
然后确保已将composer供应商目录添加到PATH系统变量中(说明),方法是附加以下内容:
Then make sure you have added the composer vendor directory to the PATH system variable (instructions) by appending the following:
; C:\Users\ [username] \AppData\Roaming\Composer\vendor\bin\
;C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\
然后开始运行:
psysh
如果您想要更好的控制台体验,建议您使用 cmder 代替Windows命令提示符。
If you want an even console better experience, I suggest you use cmder instead of the Windows Command Prompt.
这篇关于如何在Windows的交互式CLI中运行php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!