Popen.communicate()
документация:
Примечание, что, если Вы хотите отправить данные в process’s stdin, необходимо создать объект Popen с stdin=PIPE. Точно так же для получения чего-либо ни кроме Одного в кортеже результата необходимо дать stdout=PIPE и/или stderr=PIPE также.
Замена os.popen*
pipe = os.popen(cmd, 'w', bufsize)
# ==>
pipe = Popen(cmd, shell=True, bufsize=bufsize, stdin=PIPE).stdin
Предупреждение Использование связываются (), а не stdin.write (), stdout.read () или stderr.read () для предотвращения мертвых блокировок из-за любого из других буферов канала ОС, заполняющихся и блокирующихся дочерний процесс.
, Таким образом, Ваш пример мог быть записан следующим образом:
from subprocess import Popen, PIPE, STDOUT
p = Popen(['grep', 'f'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
grep_stdout = p.communicate(input=b'one\ntwo\nthree\nfour\nfive\nsix\n')[0]
print(grep_stdout.decode())
# -> four
# -> five
# ->
На текущей версии Python 3, Вы могли использовать subprocess.run
, чтобы передать вход как строку к внешней команде и получить ее статус выхода и ее вывод как строка назад в одном вызове:
#!/usr/bin/env python3
from subprocess import run, PIPE
p = run(['grep', 'f'], stdout=PIPE,
input='one\ntwo\nthree\nfour\nfive\nsix\n', encoding='ascii')
print(p.returncode)
# -> 0
print(p.stdout)
# -> four
# -> five
# ->
It sounds like you need to configure an MTA, or find one that you can send to. Ubuntu desktop should set one up by default, probably either exim or postfix, but if you haven't configured it, it will unlikely to be running.
You don't want to set the default transport if you wish to use sendmail (it is the default) and SMTP is different.
That it doesn't send the emails suggests that sendmail or the MTA on your server is not installed/not setup correctly.