【发布时间】:2012-10-10 03:02:04
【问题描述】:
import os
dictionaryfile = "/root/john.txt"
pgpencryptedfile = "helloworld.txt.gpg"
array = open(dictionaryfile).readlines()
for x in array:
x = x.rstrip('\n')
newstring = "echo " + x + " | gpg --passphrase-fd 0 " + pgpencryptedfile
os.popen(newstring)
我需要在 for 循环中创建一些东西来读取 gpg 的输出。当gpg输出这个字符串gpg: WARNING: message was not integrity protected时,我需要循环关闭并打印成功!
我该怎么做,背后的原因是什么?
谢谢大家!
【问题讨论】:
-
您使用的是
for循环,而不是while循环。 -
您应该考虑使用
subprocess.Popen而不是现在已弃用的os.popen -
另外,
gpg是否将其写入stderr或stdout? -
我可以对 subprocess.Popen 使用相同的字符串连接吗?
-
你有没有考虑过使用pygpgme来处理解密而不是直接调用gpg?
标签: python while-loop