Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于发送电子邮件的shell命令在python子进程调用中不起作用_Python_Shell_Email - Fatal编程技术网

用于发送电子邮件的shell命令在python子进程调用中不起作用

用于发送电子邮件的shell命令在python子进程调用中不起作用,python,shell,email,Python,Shell,Email,我使用shell中的邮件命令发送电子邮件: echo "abc" | mail -s "Subject" abc@def.com 我想在python中使用此命令,因此我编写了以下代码: call("echo abc" "|" "mail", "-s Subject", "abc@def.com", shell=True) 然后它给出了以下错误: Original exception was: Traceback (most recent call last): File "email.p

我使用shell中的邮件命令发送电子邮件:

echo "abc" | mail -s "Subject" abc@def.com
我想在python中使用此命令,因此我编写了以下代码:

call("echo abc" "|" "mail", "-s Subject", "abc@def.com", shell=True)
然后它给出了以下错误:

Original exception was:
Traceback (most recent call last):
  File "email.py", line 7, in <module>
    call("mail", "-s", "Subject", "abc@def.com", shell=True)
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 629, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
原始异常是:
回溯(最近一次呼叫最后一次):
文件“email.py”,第7行,在
呼叫(“邮件”、“-s”、“主题”、”abc@def.com“,shell=True)
文件“/usr/lib/python2.7/subprocess.py”,第493行,在调用中
返回Popen(*popenargs,**kwargs)。等待()
文件“/usr/lib/python2.7/subprocess.py”,第629行,在__
raise TypeError(“bufsize必须是整数”)
TypeError:bufsize必须是整数

出现这种情况的原因是什么?

尝试调用这样的
call
方法

call(["mail", "-s", "'Subject'", "abc@def.com"], shell=True)
第2部分:

sudo touch /var/mail/<username>
sudo chown <username>:mail /var/mail/<username>
sudo chmod o-r /var/mail/<username>
sudo chmod g+rw /var/mail/<username>
sudotouch/var/mail/
sudo chown:mail/var/mail/
sudo chmod o-r/var/mail/
sudo chmod g+rw/var/mail/

摘自

我实际上应该键入:call([“邮件”,“-s主题”,”abc@def.com“],shell=True)。但它给出了另一个错误:无法打开邮箱/var/mail/rex:Permission denied,因此您的now方法调用是正确的。当您从shell和同一用户运行此命令时,是什么赋予了此命令的。此/var/mail/rex的权限是否正常?是。Shell没有问题。我更新了问题。为了避免微妙的问题,我在shell中添加了echo以传递电子邮件的内容。因为如果我直接发送邮件,它会弹出提示,让我输入CC和内容。但问题依然存在。Shell工作正常,但是python给了我权限错误。请提供call(['whoami',Shell=True)和(来自Shell)ls-lah/var/mail/rex的输出