On python 2.7, I used subprocess.call(my_cmd)
when running a shell command.
However, I needed to check outputs of those commands, so I replaced them with subprocess.Popen.communicate()
.
command_line_process = subprocess.Popen(my_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process_stdout, process_stderr = command_line_process.communicate()
logging.info(process_stdout)
logging.info(process_stderr)
Is there a difference between the two methods other than the latter one can print outputs?
I wonder whether it'd be okay to replace all subprocess.call()
with subprocess.Popen.communicate()
.