[Tutor] Running EXE file with arguments

eryksun eryksun at gmail.com
Sat Mar 9 02:25:59 CET 2013


On Fri, Mar 8, 2013 at 1:37 PM, 3n2 Solutions <3n2solutions at gmail.com> wrote:
> subprocess.check_call(['c:/FinalTest/fix.exe', '-com 17','-baud
> 38400', '-setconfig base.dat'])

You can use a single string for the command on Windows. subprocess
will create one anyway, but let's stick with a list, split on the
spaces in the string.

Since the command works in the shell from the exe directory, try
setting the current working directory (cwd) to C:\FinalTest:

    import sys
    import os
    import subprocess

    exepath = 'c:\\FinalTest'
    exefile = 'fix.exe'
    cfgfile = 'base.dat'

    exe = os.path.join(exepath, exefile)
    cmd = [exe, '-com', '17', '-baud', '38400', '-setconfig',
           cfgfile]

    try:
        subprocess.check_call(cmd, cwd=exepath)
    except subprocess.CalledProcessError as e:
        # exit, logging, etc
        sys.exit(str(e))


More information about the Tutor mailing list