jat*_*ism 17
这有什么问题?
output = run('ls /path/to/files')
files = output.split()
print files
Run Code Online (Sandbox Code Playgroud)
查看文档run()
了解更多技巧.
我认为最好的方法是编写一个BASH(其他shell表现相似)oneliner.检索目录中的文件列表.
for i in *; do echo $i; done
Run Code Online (Sandbox Code Playgroud)
所以返回绝对路径的完整解决方案:
from fabric.api import env, run, cd
env.hosts = ["localhost"]
def list_dir(dir_=None):
"""returns a list of files in a directory (dir_) as absolute paths"""
dir_ = dir_ or env.cwd
string_ = run("for i in %s*; do echo $i; done" % dir_)
files = string_.replace("\r","").split("\n")
print files
return files
def your_function():
"""docstring"""
with cd("/home/"):
list_dir()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9711 次 |
最近记录: |