Running an external program (executable) with parameters in python

13,766
program = 'ztac.exe'
arguments = ('safe', 'normal', 'debug')
argument = raw_input('Enter your argument: ')
if argument in arguments:
  subprocess.call([program, argument])
else:
  print('Illegal Argument')
Share:
13,766
user591821
Author by

user591821

Updated on June 04, 2022

Comments

  • user591821
    user591821 about 2 years

    I am trying to automate a command line program.

    The exe file takes one argument to run. For example:

    ztac.exe <mode> (where mode options are safe, normal or debug).

    To run in debug mode I simply type this in the command line:

    C:\source>ztac debug

    How do I write a Python program to run this ztac.exe file while taking the different modes as inputs?

  • user591821
    user591821 over 13 years
    Thanks! That works, however, I cannot run any other code while this is running. there a os.spawn type of implementation that can help me dos this?