In a task, I need to call an external program that run on terminal via python. This external program has lots of positional and optional arguments.
Here is the sample code developed sofar:
def multi_character_parameter():
parser = argparse.ArgumentParser()
parser.add_argument('b',
help="Execute tests with browser 'firefox' or 'chrome', or 'ALL")
parser.add_argument('C', help="Execute tests in cloud 'aws' or 'azure'")
parser.add_argument(
'c', help="Clear output and temp directory before executing tests")
parser.add_argument('d', help="Check syntax for test data")
parser.add_argument("--upper-case", default=False, action="store_true")
...
args = parser.parse_args()
def my_external_program():
subprocess.call(["external_program"])
Could someone please suggest:
- How to supply these args to the external_program called via subprocess.
i.e. upon running say python script.py some_args, these some_args will be supplied to the external_program function for execution as external_program some_args.
- What would be the better way to structure the code if the
argsspecified in the code needs to be used at other parts of the code.