在Jenkins的Python脚本中模拟用户输入


这个需求很少见,但是好不容易试验成功了,所以要记录下来备忘。

我们使用Jenkins+TexturePacker进行资源的自动打包和转换。

TexturePacker首次运行需要在命令行中输入agree进行版权声明的用户确认。而Jenkins的系统环境是独立于桌面系统的,所以在Jenkins里面要再一次输入agree。于是就有了一个非常恶心的情况,Jenkins里面运行TexturePacker命令行没有给用户输入agree的地方。

幸好有万能的python脚本。它可以模拟用户的输入。这样只需要在Jenkins里面执行一下这个脚本(建立一个Job,Execute Shell里面运行如下脚本)

#!python.exe
import subprocess
halls = subprocess.Popen([r'D:\Workspace\TexturePacker\bin\TexturePacker.exe'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) 
result = halls.communicate(input=r'agree')[0] 
print halls.returncode
print halls.communicate()


评论关闭