如何在Python 2.7中执行shell命令?

时间:2017-04-08 06:19:22

标签: python-2.7 shell

Written both shell and oython codes for understanding

请帮助在python中实现shell的输出

1 个答案:

答案 0 :(得分:0)

你可以使用Popen在python中连接stdin和stdout进程,但是通常最容易让shell shell完成工作,例如你可以:

subprocess.check_output('ls | grep something', shell=True)

相关:How do I use subprocess.Popen to connect multiple processes by pipes?