why should we use stdout=PIPE in subprocess.Popen?

折月煮酒 提交于 2019-12-04 17:48:27

Remove the print() call to see the difference.

When you do not pipe the ls output to Python, it is instead displayed on your terminal directly; it's output goes to your terminal. If you pipe it to Python, you get to see the whole contents as bytes, including newline bytes (represented as \n).

Decode the results if you want the newlines to be printed literally:

print(out.decode('utf8'))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!