How do I execute a program from Python? os.system fails due to spaces in path

后端 未结 10 990
一生所求
一生所求 2020-11-22 08:19

I have a Python script that needs to execute an external program, but for some reason fails.

If I have the following script:

import os;
os.system(\"C         


        
10条回答
  •  耶瑟儿~
    2020-11-22 09:06

    For Python 3.7, use subprocess.call. Use raw string to simplify the Windows paths:

    import subprocess
    subprocess.call([r'C:\Temp\Example\Notepad.exe', 'C:\test.txt'])
    

提交回复
热议问题