For training reasons im trying to write a python script that creates and sets user accounts and passwords :
import subprocess
from subprocess import Popen
users = ["user1"]
default_passwd = 'password'
for user in users:
p1 = subprocess.Popen(["useradd" ,user])
proc = Popen(['echo' ,default_passwd , '|' , 'passwd', user, '--stdin'])
proc.communicate()
While the user is created , the passwd process fails. Any help would be appreciated.
subprocess.PIPEfor communication between processes.