[HELP!] a doubt about entering password in python
python at mrabarnett.plus.com
Fri Jan 18 05:00:29 CET 2013
On 2013-01-18 03:12, Steven D'Aprano wrote:
> On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote:
>> i use Popen to execute "su -c 'fdisk -l'" in sub process,and
>> assigned subprocess.PIPE to stdin,stdout i tried to enter password
>> by doing "stdin.write("password"+"\n")" and i expected i could get
>> the output of "fdisk -l" by doing "stdout.read()"
>> it didn't work.
>> will somebody tell me what is going on with that?
> Would you like us to guess what happened? I love guessing games!
> My guess is that it output "su: incorrect password", which means you have
> the wrong password. Is that it?
> If not, my guess is that it output "fdisk: command not found", in which
> case your system is broken and the fdisk binary is missing or not on the
> PATH. Am I close?
> Last guess: you got a Python traceback with an error:
> NameError: name 'subprocess' is not defined
> You need to import the subprocess first.
> If none of my guesses are correct, could we have some hints? Perhaps show
> us the actual code you are using, and the actual results, copied and
> pasted exactly.
It may, of course, be that for security reasons it won't accept a
whatever happens to be connected to stdin, but instead insists that it's
directly from the keyboard, if you see what I mean.
More information about the Python-list