【问题标题】:execute python file from python script with arguments{jenkins]从带有参数的python脚本执行python文件{jenkins]
【发布时间】:2018-04-13 17:38:13
【问题描述】:

我正在运行一个 python 脚本。 环境:Windows10 蟒蛇版本:2.7.14 我正在尝试在 jenkins 中运行这个文件执行批处理命令(一般用于 windows 命令行选项) 这是代码。

p1.py:

import subprocess
command="C:/users/python test1.py C:/Users/test1.html"
subprocess.call(command,shell=True)

从 Jenkins 运行时总是抛出错误:

C:\Python27\python.exe: can't find '__main__' module in 'C:\\Users\\'

C:\Users\test\.jenkins\workspace\test1>python p1.py 
python: can't open file 'p1.py': [Errno 2] No such file or directory

但是当我从命令提示符下运行它时同样有效。

我在这里遗漏了什么吗?

我试过了

os.system("python p1.py test1.html")

但我得到了同样的错误。

编辑:它现在可以工作了,缺少的是系统路径

【问题讨论】:

  • C:\Users\C5242046\.jenkins\workspace\test1\p1.py 存在吗?
  • 是的,存在......但我现在已经改变了它,因为当我问这个存在但现在它不存在的问题时

标签: python python-2.7 jenkins subprocess


【解决方案1】:

我用exec(open(“myfile.py”).read())

【讨论】:

  • 请注意,我也必须将 html 文件 (test1.html) 作为 sys 参数传递,并且我也尝试过 exec 选项。
猜你喜欢
  • 1970-01-01
  • 2013-04-08
  • 1970-01-01
  • 2012-08-21
  • 1970-01-01
  • 2011-12-03
  • 1970-01-01
  • 2013-10-21
相关资源
最近更新 更多