简体   繁体   中英

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. 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). 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

which I understand as i did not add a file src like i did in the terminal by adding output.xml

I cant add output.xml as paramter to modl.DbBot() as it takes no parameters. How does one pass the -k flag and the output.xml (file src) from withing a script?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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