Найти - Пользователи
Полная версия: Ввод пароля в shell
Начало » Python для новичков » Ввод пароля в shell
1
Enchantner
Как на питоне разрешить ситуацию, когда после ввода команды в shell спрашивается пароль? Это может быть, в частности, sudo или что-то в этом роде. Shell-команды я выполняю в основном с помощью os.popen(). Как передать пароль в shell программно?
Enchantner
Пытаюсь так:
from subprocess import PIPE, Popen
proc = Popen(command, shell=True, stdin=PIPE, stdout=PIPE)
proc.stdin.write(mypass + '\n')
Выдает, что неверный пароль.
Enchantner
Все, разобрался
slivlen
Советую посмотреть еще в сторону pexpect(http://pexpect.sourceforge.net/pexpect.html).
sypper-pit
описывай что у тебя было и кк ты решил…
Enchantner
sypper-pit
from subprocess import Popen, PIPE
proc = Popen(command, shell=True, cwd=self.fullpath, stdin=PIPE, stdout=PIPE)
proc.communicate(mypass)
proc.wait()
А вообще исходники проекта тут, можете глянуть: http://pastebin.mozilla-russia.org/99375
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB