简体   繁体   English

python从带参数的脚本运行脚本

[英]python run script from script with arguments

For a python 2.7 project I want to read robotframework output.xml to a sqlite database, I found the package DbBot which does exactly that. 对于一个python 2.7项目,我想将robotframeworkwork output.xml读取到sqlite数据库中,我找到了DbBot软件包,它正是这样做的。 However i want to run it from a script instead of from the command line. 但是我想从脚本而不是从命令行运行它。 The command I use on the command line is: 我在命令行上使用的命令是:

python -m dbbot.run -k output.xml

which does exactly what I want (generate a sqlite database with the right data). 这正是我想要的(使用正确的数据生成一个sqlite数据库)。 I tried the following: 我尝试了以下方法:

modl = imp.load_source('modulename', 'C:/Python27/Lib/site-packages/dbbot/run.py')
someRunner = modl.DbBot()

which returns: 返回:

Run.py: error: at least one input file is required Run.py:错误:至少需要一个输入文件

which I understand as i did not add a file src like i did in the terminal by adding output.xml 据我了解,因为我没有像在终端中那样通过添加output.xml来添加文件src

I cant add output.xml as paramter to modl.DbBot() as it takes no parameters. 我无法将output.xml作为参数添加到modl.DbBot(),因为它不带任何参数。 How does one pass the -k flag and the output.xml (file src) from withing a script? 如何通过脚本传递-k标志和output.xml(文件src)?

Use subprocess package: 使用子流程包:

import subprocess

# run separate process
subprocess.call(['python', '-m', 'dbbot.run', '-k', 'output.xml'], shell=False)

dbbot.run is not coded to run from inside another script. dbbot.run没有被编码为从另一个脚本内部运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM