我是EE,试图用Python编写一个脚本来简化文件检查。 由于某些原因,我们的IT将不允许我访问我们的smtp服务器,并且只允许通过mailx发送邮件。 所以,我想从Python运行mailx并发送它,就像它在我的控制台中一样。唉,这是个例外。请参阅下面的Linux日志:
***/depot/Python-3.1.1/bin/python3.1
Python 3.1.1 (r311:74480, Dec 8 2009, 22:48:08)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> process=subprocess.Popen('echo "This is a test\nHave a loook see\n" | mailx -s "Test Python" mymail@mycomopany.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/depot/Python-3.1.1/lib/python3.1/subprocess.py", line 646, in __init__
errread, errwrite)
File "/depot/Python-3.1.1/lib/python3.1/subprocess.py", line 1146, in _execute_child
raise child_exception***
我是Python的新手(现在从PERL迁移)。有什么想法吗?
你可以使用
subprocess.call
。比如:详细信息here
Lior Dagan的代码几乎是正确的/功能性的:这种方法的错误是调用
subprocess.Popen
时缺少shell=True
kwarg
。任何真正考虑这种方法的人都应该知道subprocess
文档警告:一般来说,F0RR和ghostdog74的解决方案应该是首选的,因为它们更加健壮和安全。
您可以使用smtplib
如果您真的想使用子流程(我建议您不要这样做)
相关问题 更多 >
编程相关推荐