In Python - How To Execute System Command With No Output
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 cross-platform, so
Solution 1:
import os
import subprocess
subprocess.call(["ls", "-l"], stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
Solution 2:
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.
Post a Comment for "In Python - How To Execute System Command With No Output"