是否有用于 Windows 的简单 php shell?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8480814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:38:26  来源:igfitidea点击:

is there a simple php shell for windows?

phpwindowscommand-line

提问by ewok

Is there a command line php shell available for windows? I looking for something similar to the python shell, that will allow me to open and immediately begin executing code.

是否有可用于 Windows 的命令行 php shell?我正在寻找类似于 python shell 的东西,这将允许我打开并立即开始执行代码。

采纳答案by Tim Cooper

Have a look at either running php.exe with the -aargument, or maybe the phpshproject.

看看使用-a参数运行 php.exe ,或者phpsh项目。

回答by Jonathan M

回答by Pavle Predic

Try this:

尝试这个:

<?php
$fh = fopen('php://stdin', 'r');
$cmd = '';
$bcLvl = 0;
while (true)
{
    $line = rtrim(fgets($fh));
    $bcLvl += substr_count($line, '{') - substr_count($line, '}');
    $cmd.= $line;
    if ($bcLvl > 0 or substr($cmd, -1) !== ';')
    continue;
    eval($cmd);
    $cmd = '';
}

Save this code to a file (eg shell.php) and then run it from console:

将此代码保存到文件(例如 shell.php)中,然后从控制台运行它:

php shell.php

Hit CTRL+C to exit.

按 CTRL+C 退出。

回答by Tgr

There is php-shell- it is not great, but still way better than php -a. (Also, it is dead simple to install, just run pear install http://jan.kneschke.de/assets/2007/2/17/PHP_Shell-0.3.1.tgz.) There is also phpa-norl, but I haven't tried it.

php-shell- 它不是很好,但仍然比php -a. (另外,它的安装非常简单,只需运行即可pear install http://jan.kneschke.de/assets/2007/2/17/PHP_Shell-0.3.1.tgz。)还有phpa-norl,但我还没有尝试过。

回答by Tgr

Another simple variant, influenced by other answers. Create and run the following cmd-script:

另一个简单的变体,受其他答案的影响。创建并运行以下 cmd 脚本:

@echo off
:loop
php.exe -r "while (true) { eval (fgets (STDIN) ); echo PHP_EOL; }"
goto loop

Immediate execution, Ctrl+C for exit. Insert correct path before "php.exe".

立即执行,Ctrl+C 退出。在“php.exe”之前插入正确的路径。

回答by vikyd

@Pavle Predic 's answer (https://stackoverflow.com/a/15742101/2752670) works for me on Windows.

@Pavle Predic 的答案(https://stackoverflow.com/a/15742101/2752670)在 Windows 上对我有用。

But I want to use the shell.phpfile anywhere, so my solution is:

但我想在shell.php任何地方使用该文件,所以我的解决方案是:

  1. new and save shell.phpin php installed dir (or where else you like), e.g. C:\Program Files\php-5.6.12-Win32-VC11-x64\shell.php

  2. new a Windows environment variable, key: shell.php, value: "C:\Program Files\php-5.6.12-Win32-VC11-x64"

  3. restart computer

  4. use anywhere in the system:

    php %shell.php%

  1. 新建并保存shell.php在 php 安装目录(或其他你喜欢的地方),例如C:\Program Files\php-5.6.12-Win32-VC11-x64\shell.php

  2. 新建一个Windows 环境变量,键:shell.php,值:"C:\Program Files\php-5.6.12-Win32-VC11-x64"

  3. 重启电脑

  4. 在系统的任何地方使用:

    php %shell.php%

回答by Vijay

I found these two on github as well:

我在github上也找到了这两个:

回答by Tgr

PsySHis the best REPL shell I have seen recently. Tab-completion, phpdoc support, proper namespace handling, interactive debugging, plugin support and many more. It is pure PHP and has composer support so it should be easy to install on Windows. I have only tried it on Linux but looking at the code, it seems to even have some history support on OSes without readline.

PsySH是我最近看到的最好的 REPL shell。Tab 完成、phpdoc 支持、正确的命名空间处理、交互式调试、插件支持等等。它是纯 PHP 并支持作曲家,因此应该很容易在 Windows 上安装。我只在 Linux 上尝试过,但查看代码,它似乎甚至在没有 readline 的操作系统上也有一些历史支持。

回答by m3nda

Maybe answered - Read here: https://stackoverflow.com/a/19085620/2480481I think i found easiest way to do it because im so interested to use myself :)

也许回答 - 在这里阅读:https: //stackoverflow.com/a/19085620/2480481我想我找到了最简单的方法,因为我很想使用自己:)

I try all options from here and from some other forums/pages... Windows cannot use readline.

我尝试了这里和其他一些论坛/页面的所有选项...... Windows 无法使用 readline。