【问题标题】:Having issues reading a remote file while using subprocess使用子进程时读取远程文件时出现问题
【发布时间】:2015-01-08 17:36:42
【问题描述】:

我执行以下操作,但无法逐行读取文件“word_file.txt”..

 f = subprocess.Popen(["../../../script.sh", "cat", "word_file.txt"], stdout=subprocess.PIPE)
            out = f.stdout.readline()
            print "......."
            for i in f.stdout.readline():
                print "I>>>>>>>>>>>", i

被打印的 i 分别打印每个字符。

所以,我试着做..

for i in f.stdout.readline().split('\n'):
            print "I>>>>>>>>>>>", i

Read remote file using python subprocess and ssh? - 解决了同样的问题,但他们的解决方案对我不起作用。

但这似乎不正确。我没有输出..

【问题讨论】:

  • 试试iter(f.stdout.readline,"")
  • iter(f.stdout.readline(),"") TypeError: iter(v, w): v must be callable -> 我得到两行错误..
  • readline 上没有括号,
  • 我没有输出,帕德莱克!删除括号后
  • 我没有完全理解您的问题,您是否从问题中的任何一种尝试中获得输出?你也在使用for i in iter(f.stdout.readline,"")?

标签: python file subprocess cat


【解决方案1】:

使用iterreadline 读取每一行:

for i in iter(f.stdout.readline,"")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-30
    • 2011-10-31
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多