I've been trying to communicate with a program (smbpasswd) using Python's subprocess module without much success. I can communicate with a different program, (e.g. grep) without any trouble, so the problem is specific to smbpasswd. To illustrate the problem, the following code works:
>>> p = Popen(["grep", "n"], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
>>> stdout = p.communicate(input='one\ntwo\n')[0]
>>> print(stdout)
one
However, the following does not:
>>> p = Popen(["smbpasswd", "-r", server, "-U", user], stdout=PIPE, stdin=PIPE, stderr=PIPE)
>>> stdout = p.communicate(input='old_password')[0]
>>> print(stdout)
The difference is that grep waits for user input after calling the initial "grep f", while smbpasswd prompts the user to input their old password ("Old SMB password:" is displayed if you run the command in a terminal) before looking for input.
This is, however, where my knowledge ends. Any help is greatly appreciated!