使用python和p4v获取标签的日期

时间:2014-06-15 14:30:40

标签: python perforce labels os.system

我正在尝试获取标签的日期。我知道的cmd命令是:

p4 labels -e the_label_name

确实给了我以下内容:

Label the_label_name 2014/06/05 00:05:13 'Created by mebel. '

要使用python,我写道:

os.system("sc labels -t -e the_label_name")

我得到的是:

Label the_label_name 2014/06/05 00:05:13 'Created by mebel. '

0

但是,如果我写

label = os.system("sc labels -t -e the_label_name")

我明白了

label = 0

你知道我错过了什么吗?

2 个答案:

答案 0 :(得分:0)

根据os.system的文档,返回值是程序的退出状态。

如果要检索程序的输出,可以使用subprocess中的check_output函数:

import subprocess
label = subprocess.check_output("sc labels -t -e the_label_name", shell=True)

示例:

>>> import subprocess
>>> subprocess.check_output("shuf -n 1 /usr/share/dict/words", shell=True)
>>> 'monkey-pot\n'

答案 1 :(得分:0)

我发现了这个:

label = os.popen("sc labels -e the_label_name")
label = label.read()

修复了一切...