我正在尝试在一个xml文件中std。我从subversion读取了xml文件,更新了文件中的一行,现在我尝试使用副总统大人和stdin
test = subprocess.Popen('svn cat http://localhost/svn/WernerTest/JenkinsJobTemplates/trunk/smartTemplate.xml --username admin --password admin', stdout=subprocess.PIPE, universal_newlines=True)
job = test.stdout.read().replace("@url@", "http://localhost/svn/WernerTest/TMS/branches/test1")
output = io.StringIO()
output.write(job)
subprocess.Popen('java -jar D:\\applications\\Jenkins\\war\\WEB-INF\\jenkins-cli.jar\\jenkins-cli.jar -s http://localhost:8080/ create-job test7', stdin=output)
我得到了以下错误:
^{pr2}$那么如何将更新后的文件传递给下一个子进程呢?在
使用管道并将数据直接写入该管道:
^{} method 接受第一个参数并将其作为stdin发送到子进程。在
注意,我也为Jenkins设置了^{} argument 为
True
;另一种方法是将job
字符串显式编码为Jenkins可以接受的合适的编解码器。在Popen()
只接受真实的文件(至少是有效的.fileno()
)。 @Martijn Pieters♦' answer显示了如果您可以一次将所有数据加载到内存中,如何传递数据(另外,jenkins
进程直到svn
产生all输出才会启动)。在下面是如何一次读取一行(svn和jenkins进程并行运行):
请参见下面的
svn_cmd
,java_cmd
定义(在Windows上不需要shlex.split(cmd)
注意:不shell=True
)。在如果您不需要替换
^{2}$@url@
,那么它看起来就像您正在尝试模拟:svn_cmd | java_cmd
管道,其中:最简单的方法就是把贝壳搅得七零八落:
您可以在Python中模拟它:
见How do I use subprocess.Popen to connect multiple processes by pipes?
相关问题 更多 >
编程相关推荐