On Wed, Apr 25, 2012 at 12:21 PM, 叶佑群 <ye.you...@eisoo.com> wrote: > Hi, all > > I have code as: > > pobj = subprocess.Popen (["smbpasswd", user], stdin > =subprocess.PIPE) > password += "\n" > pobj.stdin.write (password) > pobj.stdin.write (password) > > the command smbpasswd will change the samba user's password, In shell > this will run as below: > > [root@localhost ~]# smbpasswd mytest1 > New SMB password: > Retype new SMB password: > [root@localhost ~]# > > but in python code, it always prompt to wait input the password, it is > seems that pobj.stdin.write () doesn't work. It is anything wrong with my > code? I have another block code that runs as expected: >
Maybe smbpasswd does not read the password from stdin. Some programs prefer to open the terminal /dev/tty directly and read from it. You will not be able to use subprocess directly with such programs. You have some options: - find out if the smbpasswd has an option that will make it read the password from stdin - use an expect-like library, such as pexpect -- regards, kushal -- http://mail.python.org/mailman/listinfo/python-list