Linux find 命令在python中的实现 [英] Implementation of the Linux find command in python

查看:33
本文介绍了Linux find 命令在python中的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能给我指出一组如何在 Python 脚本中实际实现和使用 find 命令的说明吗?

Can someone point me to a set of instructions of how to actually implement and utilize the find command within a Python script?

我看过:https://docs.python.org/2/library/subprocess.html我不确定如何使用该命令,即使 subprocess.callsubprocess.Popen 的实现都很顺利.从我读过的所有关于这个主题的 SO 线程来看,这似乎是两个最好的选择.但是,我不确定我需要使用什么样的参数,以及如何在其中具体实现 find 命令.

I have looked at: https://docs.python.org/2/library/subprocess.html I'm not exactly sure how to utilize the command, even if implementation goes well with either subprocess.call or subprocess.Popen. From all of the SO threads that I've read concerning this topic, it seems like these are the two best options. However, I am not sure what kind of arguments I would need to use, as well as how to specifically implement the find command within them.

有人可以演示如何在 subprocess.callsubprocess.Popen 的上下文中使用 find 以便我以后可以调用 find 直接在我的 Python 脚本中?

Can someone please demonstrate how to use find in the context of subprocess.call or subprocess.Popen so that I can later call find directly in my Python script?

推荐答案

这个怎么样,

found = subprocess.Popen(['find', '.'],stdout=subprocess.PIPE)
for line in iter(found.stdout.readline, ''):
   print line,

这篇关于Linux find 命令在python中的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆