Pass arguments to executable in Python

后端 未结 1 1013
醉话见心
醉话见心 2020-12-20 00:38

I am using os.startfile(\'C:\\\\test\\\\sample.exe\') to launch the application. I don\'t want to know the application’s exit status and I just want to launch t

相关标签:
1条回答
  • 2020-12-20 01:21

    You should use the subprocess module instead of os.startfile or os.system in every case that I'm aware of.

    import subprocess
    subprocess.Popen([r'C:\test\sample.exe', '-color'])
    

    You could, as @Hackaholic suggests in the comments, do

    import os
    os.system(r'C:\test\sample.exe -color')
    

    But this is no simpler, and the docs for os recommend the use of subprocess instead.

    0 讨论(0)
提交回复
热议问题