最近看到了https://blog.csdn.net/u013412391/article/details/126588701,想试着自己写个功能用在项目上,想在不使用P4api的情况下通过subprocess模块连接perforce并创建一个ChangList,并且在创建的过程中就能够通过变量来输入description。尝试了一下直接通过command实现是能够实现的。
p4 --field "Description=My pending change" change -o | p4 change -i
但是如果直接通过输入subprocess.Popen('p4 --field "Description=My pending change" change -o | p4 change -i ')是不能够进行创建的。随后又找到了https://stackoverflow.com/questions/14286418/is-there-a-way-to-create-a-new-p4-changelist-using-python-subprocess 做为参考,直接复制里面的代码会返回
TypeError: a bytes-like object is required, not 'str'
所以我将我所输入的str转变为了bytes,不报错了但是返回的是空值。并且perfoce上并没有创建新的ChangeList
def create_new_CL():
descr = b"this is a test description"
changespec = b"change: New\ndescription: " + descr
p = subprocess.Popen('p4 change -i', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate(changespec)
print (out.decode('utf-8'))
想知道为什么运行不了以及有没有什么办法实现我想要的功能,目前配置的环境是py3
修改一下args参数试试看
不一样啊,你是用的str,他用的是list
descr = "this is a test description"
changespec = "change: New\ndescription: " + descr
p = subprocess.Popen(["p4","change","-i"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate(changespec)
print out
朋友,每个 changelist其实是某些特定版本文件的集合,但是并不是所有的版本的文件结合都对应到一个changelist。perforce允许用户将 workspace同步到文件的某些特定版本,不一定对应一个chagnelist。
你这边可以先通过以下三步来确定workspace的最新状态
p4 changes 命令可以查看workspace中文件集合所对应的最高chagnelist:
p4 changes -m1 //...#have
可以使用如下命令查看workspace中是否所有的文件都被sync到了最高changelist:
p4 sync -n @
import subprocess
descr = "this is a test description"
changespec = "change: new\ndescription: " + descr
p = subprocess.Popen(["p4","change","-i"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate(changespec.encode())
print (out, err)