[HELP!] a doubt about entering password in python

douxin wq-doux at cn.fujitsu.com
Thu Jan 17 21:49:30 EST 2013


Hi all:

    i have some doubts in doing python programming

    i wanted to execute a command "su -c 'fdisk -l'",and it needed a
    password
    so i wanted to write a python script to get this done.

    i knew 'pexpect' would work fine,but i had to set a certain timeout
    to take care of the real delay time which i probably didn't know

    i tried to use 'subprocess' to do this,however,it did not work
    well,and came the problem

    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?
    i'll appreciate i can learn from you

    Dou

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130118/7bfcbf15/attachment.html>


More information about the Python-list mailing list