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

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

问题描述

我目前正在为OS X上的Sublime Text 2开发几个插件,我想使它们跨平台,这意味着我必须确定php.exe的安装位置.

现在我用Python调用/usr/bin/php,它显然仅在OS X和Linux上有效:

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

但是在Windows上,似乎没有definitve php.exe的默认路径.我搜索的次数越多,出现的可能性就越大.到目前为止,我认为我必须检查以下每种路径的存在:

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

这已经是一个集合,但是我要的是包含所有可能性的完整列表-找出它应该的另一种方式是健壮,可检查每个可能的路径.

因此,如果您在除此以外的其他位置安装了php.exe,请在路径中添加注释,我将其添加到上面的列表中.

此外,似乎还有php.exephp-cli.exe.我想可以遍历每个可能的路径,首先检查php-cli.exe,然后检查php.exe并进行第一个匹配.那是正确的还是有更好的做法?

解决方案

如果用户已定义将PHP的bin文件夹添加到系统PATH,则您应该能够尝试执行php -v来检查它是否存在.

如果要获取php可执行文件的完整路径,并且目标系统是Windows 2003或更高版本(因此是Vista和7),则可以使用WHERE命令,即:

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

另请参阅可能的相关问题:是否存在与在Windows命令行上?.

如果您真的很想在用户计算机上找到任何文件,则可以尝试执行find的等价文件-但这将是 slooow

C: && cd \ && dir /s /b 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.

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 ) )

But on Windows, there seems to be no definitve default path for php.exe. The more I googled for it, the more possibilies 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 possibilties - or another way to figure it out that should be as robust as checking each possible path.

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.

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

解决方案

If the user has defined 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.

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

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

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

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

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

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

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