General Tips¶
The method
subprocess.runis preferred over older high-level APIs (subprocess.call,subprocess.check_callandsubprocess.check_output). The methodsubprocess.Popen(which powers the high-level APIs) can be used if you need advanced controls. When running a shell command usingsubprocess.run,Avoid using system shell (i.e., avoid using
shell=True) for 2 reasons. First, avoid shell injection attack. Second, there is no need for you to manually escape special characters in the command.