如何从 Python 调用 Perl 脚本,将输入传递给它? [英] How to call a Perl script from Python, piping input to it?
问题描述
我正在将一些对 DomainKeys 和 DKIM 的支持添加到一个开源电子邮件营销程序中,该程序使用 Python 脚本通过 SMTP 发送实际电子邮件.我决定走快速而肮脏的路线,只编写一个 perl 脚本,它接受来自 STDIN 的电子邮件,对其进行签名,然后将其返回.
I'm hacking some support for DomainKeys and DKIM into an open source email marketing program, which uses a python script to send the actual emails via SMTP. I decided to go the quick and dirty route, and just write a perl script that accepts an email message from STDIN, signs it, then returns it signed.
我想做的是从 python 脚本中,将字符串中的电子邮件文本通过管道传输到 perl 脚本,并将结果存储在另一个变量中,这样我就可以发送已签名的电子邮件.然而,我并不完全是一个 python 大师,我似乎找不到一个好的方法来做到这一点.我很确定我可以为此使用 os.system
之类的东西,但是将变量通过管道传递给 perl 脚本似乎是我无法理解的事情.
What I would like to do, is from the python script, pipe the email text that's in a string to the perl script, and store the result in another variable, so I can send the email signed. I'm not exactly a python guru, however, and I can't seem to find a good way to do this. I'm pretty sure I can use something like os.system
for this, but piping a variable to the perl script is something that seems to elude me.
简而言之:如何将变量从 python 脚本传递到 perl 脚本,并将结果存储在 Python 中?
In short: How can I pipe a variable from a python script, to a perl script, and store the result in Python?
我忘了包括我正在使用的系统只有 python v2.3
I forgot to include that the system I'm working with only has python v2.3
推荐答案
os.popen() 将返回一个包含子进程的标准输入和标准输出的元组.
os.popen() will return a tuple with the stdin and stdout of the subprocess.
这篇关于如何从 Python 调用 Perl 脚本,将输入传递给它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!