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

后端 未结 10 991
一生所求
一生所求 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条回答
  •  萌比男神i
    2020-11-22 09:00

    For python >= 3.5 subprocess.run should be used in place of subprocess.call

    https://docs.python.org/3/library/subprocess.html#older-high-level-api

    import subprocess
    subprocess.run(['notepad.exe', 'test.txt'])
    

提交回复
热议问题