前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Read Output From Shell

Read Output From Shell

作者头像
技术小黑屋
发布2018-09-04 16:28:02
7160
发布2018-09-04 16:28:02
举报
文章被收录于专栏:技术小黑屋技术小黑屋

Python provides a lot of method to read output from a just executed shell. However many of them has been deprecated(Not recommened). But subprocess works at present compared to other methods.

1 2 3 4 5 6 7 8 9 10 11 12

from subprocess import Popen,PIPE,STDOUT def readFromCommand(command) : p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) result = p.stdout.read().strip() return result print readFromCommand('ls') #result #0001-.patch #0001-.patch.zip #0001-Replace-app_name-into-Browser.patch

A detailed description about subprocess has been written down here. http://docs.python.org/2/library/subprocess.html

Others

  • Python for Data Analysis: Data Wrangling with Pandas, NumPy, and IPython
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Others
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档