如何在 Windows 上确定 php.exe 的路径 - 搜索默认路径 [英] How to determine path to php.exe on Windows - search default paths

查看:133
本文介绍了如何在 Windows 上确定 php.exe 的路径 - 搜索默认路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 OS X 上为 Sublime Text 2 开发几个插件,我想让它们跨平台,这意味着我必须找出 php.exe 是否安装以及安装位置.

I'm currently developing a couple of plugins for Sublime Text 2 on OS X and I would like to make them cross platform, meaning I have to find out if and where php.exe is installed.

现在我在 Python 中调用 /usr/bin/php,这显然只适用于 OS X 和 Linux:

Right now I call /usr/bin/php in Python, which obviously works only on OS X and Linux:

phppath = '/usr/bin/php'<br>
pluginpath = sublime.packages_path() + '/HtmlTidy/tidy.php'<br>
retval = os.system( '%s "%s"' % ( phppath, scriptpath ) )

但在 Windows 上,php.exe 似乎没有明确的默认路径.我在谷歌上搜索的越多,出现的可能性就越多.到目前为止,我认为我必须检查以下每个路径是否存在:

But on Windows, there seems to be no definitive default path for php.exe. The more I googled for it, the more possibilities showed up. So far I think I would have to check each of the following paths for existence:

c:\php\php.exe
c:\php5\php.exe
c:\windows\php.exe
c:\program files\php\php.exe
c:\wamp\bin\php\php5\php.exe
c:\xampp\php\php.exe

这已经是一个相当多的集合了,但我要的是一个完整列表,涵盖所有可能性 - 另一种方法来弄清楚它应该是在检查每个可能的路径时健壮.

That's already quite a collection, but what I'm asking for is either a complete list covering all possibilities - or another way to figure it out that should be as robust as checking each possible path.

因此,如果您在其他地方安装了 php.exe,请留下您的路径的评论,我会将其添加到上面的列表中.

So if you have php.exe installed in some place other than these, please leave a comment with your path and I will add it to the list above.

另外,好像还有php.exephp-cli.exe.我想循环遍历每个可能的路径是可以的.首先检查 php-cli.exe,检查 php.exe,然后取第一个匹配项.这是正确的还是有更好的做法?

Besides, there seems to be php.exe and php-cli.exe. I guess it would be OK to loop through each possible path. Check first for php-cli.exe, check for php.exe, and take the first match. Is that correct or is there a better practice?

推荐答案

如果用户已将 PHP 的 bin 文件夹添加到系统 PATH,那么您应该可以尝试执行 php -v 检查它是否存在.

If the user has added PHP's bin folder to the system PATH, then you should just be able to try and execute php -v to check that it's present.

如果您想获取 PHP 可执行文件的完整路径并且目标系统是 Windows Server 2003 或更高版本(所以 Windows VistaWindows 7) 然后您可以使用 WHERE 命令,即:

If you want to obtain the full path to the PHP executable and the target system is Windows Server 2003 or later (so Windows Vista, and Windows 7) then you could use the WHERE command, i.e.:

C:\> where php.exe
C:\Program Files (x86)\WAMP\bin\php\php5.3.5\php.exe

另请参阅可能相关的问题:是否有等效的Windows 命令行上的哪个"?.

Also see possibly related question: Is there an equivalent of 'which' on the Windows command line?.

如果您真的很想在用户的计算机上找到任何文件,您可以尝试执行等效的find - 但它会缓慢

If you are really desperate to find any file on the user's computer, you could try executing the equivalent of a find - but it's going to be slooow!

C: && cd \ && dir /s /b php.exe

这篇关于如何在 Windows 上确定 php.exe 的路径 - 搜索默认路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆