我有以下代码
clearfile = '/tmp/jjj'
passphrase = "one fish two fish"
opts = '--no-tty --homedir=/www/vhost/.gnupg --passphrase-fd 0 -a -c -o - '
cmd = ['/usr/bin/gpg', opts, clearfile ]
print opts
print cmd
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,stdout=subprocess.PIPE)
out,err = proc.communicate(passphrase)
gpgdata = out.read()
out.close()
print gpgdata
我知道read位是错误的,但是命令失败了,因为它截断了opts,我得到了以下错误
gpg: invalid option "--no-tty --homedir=/www/vhost/.gnupg --passphrase-"
Traceback (most recent call last):
File "./test", line 26, in <module>
gpgdata = out.read()
AttributeError: 'str' object has no attribute 'read'
为什么opts字符串被截断?你知道吗
谢谢你的帮助
您应该阅读精美手册:
https://docs.python.org/2.7/library/subprocess.html?highlight=popen#subprocess.Popen
相关问题 更多 >
编程相关推荐