Executing a subprocess fails

后端 未结 2 1743
闹比i
闹比i 2020-11-27 18:11

I tried to call a process via Python with several arguments. Executing the batch file itself works fine for me but translating it into Python makes me scream. Here the conte

2条回答
  •  感动是毒
    2020-11-27 18:34

    First, you don't need all those quotes. So remove them. You only need quotes around parameters that have a filename when that filename has a space (stupidly, Windows does this often).

    Your parameters are simply a list of strings, some of which need quotes. Because Windows uses non-standard \ for a path separator, use "raw" strings for these names.

    params = [
        r'"C:\Program Files\Systems\Emb Work 5.4\arm\bin\mpr.dll"',
        r'"C:\Program Files\Systems\Emb Work 5.4\arm\bin\ajl.dll"',
        r'"C:\Documents and Settings\USER\Desktop\abc.out"',
        "--backend",
        "-B", 
        "--endian=little",
        "--cpu=Cortex",
        "--fpu=None",
        "-p",
        r'"C:\Program Files\unknown\abc.ddf"',
        "--drv_verify_download",
        "--semihosting",
        "--device=STM32F10xxB",
        "-d",
        "jjftk",
        "--drv_communication=USB0",
        "--speed=auto",
        "--initial_speed=32",
        "--reset_strategy=0,0"]
    

    Use something like

    program = r'"C:\Program Files\Systems\Emb Work 5.4\common\bin\run"'
    subprocess.Popen( [program]+params )
    

提交回复
热议问题