如何检查python安装的java、php、程序等?

如何检查python安装的java、php、程序等?,python,Python,我做了一个类似于运行前检查系统的东西,因此它符合python的要求。 这是迄今为止我的代码 def checksystem(): installednode = os.popen('node ' + srctocoffeecompiler + ' -v') // version 1.1.1 print installednode.read() 我可以打印版本,但是有没有更好的方法来检查安装的版本是否高于1.0.x?这是我到目前为止做这件事的代码 version = in

我做了一个类似于运行前检查系统的东西,因此它符合python的要求。 这是迄今为止我的代码

def checksystem():
    installednode = os.popen('node ' + srctocoffeecompiler + ' -v')
    // version 1.1.1
    print installednode.read()
我可以打印版本,但是有没有更好的方法来检查安装的版本是否高于1.0.x?这是我到目前为止做这件事的代码

version = installednode.read()
if installednode.read() == 'CoffeeScript version 1.1.1':
    // the code
    // or split the string with space then get the last array
    // check if its more then 1.1.1 or 111 ( dots removed )
*编辑我读了关于使用subprocess.Popen的文档,可能更好,不确定。我仍然得到错误没有这样的文件存在

*编辑2

pn = subprocess.Popen(['node','-v'], stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.PIPE)
print "NodeJS version: " + pn.read()
好的,我可以调用它,但我不能读取它的输出返回,java也是如此

pj = subprocess.Popen(['java','-version'], stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.PIPE)
print "JAVA: " + pj.read()

谢谢

我将拆分版本字符串,如果使用列表,比较非常简单:

>>> vers1 = '1.0.1'.split('.')
>>> vers2 = '1.0.0'.split('.')
>>> vers1
['1', '0', '1']
>>> vers2
['1', '0', '0']
>>> vers1 > vers2
True
>>> vers2 > vers1
False
>>> 
这里有一个JavaScript替代方案:

>>> var vers1 = "1.0.1".split('.');
>>> var vers2 = "1.0.0".split('.');
>>> vers1
["1", "0", "1"]
>>> vers2
["1", "0", "0"]
>>> vers1 > vers2
true
>>> vers2 > vers1
false

几乎一样;-)

python真是在炫耀D谢谢,我从来都不知道如果没有一个函数,我们在php中就不能做得很好。我仍然有一个问题,返回而不是输出
-v
,它应该返回到
installednode
,所以屏幕上没有任何内容,相反,它将位于
installednode='coffeescriptversion1.1.1'
您使用哪个Python版本?不推荐使用os.popen()。你应该使用
subprocess
.updated,是的,我现在正在使用它,新问题,我甚至无法获得返回版本。
subprocess.Popen(['java','-version'],stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE)。stderr.read()