In Python - how to execute system command with no output

后端 未结 2 778
生来不讨喜
生来不讨喜 2021-01-02 08:53

Is there a built-in method in Python to execute a system command without displaying the output? I only want to grab the return value.

It is important that it be cros

相关标签:
2条回答
  • 2021-01-02 09:39

    You can redirect output into temp file and delete it afterward. But there's also a method called popen that redirects output directly to your program so it won't go on screen.

    0 讨论(0)
  • 2021-01-02 09:43
    import os
    import subprocess
    subprocess.call(["ls", "-l"], stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
    
    0 讨论(0)
提交回复
热议问题