D
douxin
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
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