Date: Thu, 26 Mar 2015 17:03:30 -0800 From: Henrik Hudson <lists@rhavenn.net> To: freebsd-questions@freebsd.org Subject: pw -h file descriptor flag and python scripts... Message-ID: <20150327010330.GA70222@vash.rhavenn.local>
next in thread | raw e-mail | index | archive | help
Hey List, I've been trying to write a Python script that does some systems management. Part of this is to add a new user account. I'd like to set the password for this account. The route I was taking is using Python's subprocess module, but I seem to be getting stuck in that Python treats everything as strings and the pw -h option is expecting a fd (file descriptor) back. The command I'm trying to run is: /usr/sbin/pw useradd foobar2 -C /usr/local/etc/bsdmanage/etc/pw.conf -m -c "BSDmanage foobar2 user" -G foobar2-www -h I'm doing this in Python via: listCmdArgs = shlex.split(strPwUserCmd) processUser = subprocess.Popen(listCmdArgs,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE) strOutPut, strErrorValue = processUser.communicate('password') print(strOutPut + ' wa ' + strErrorValue) strPwUserCmd = the pw command from above. processUser.commmunicate wants to pass in a string value. I also tried doing it via: listCmdArgs = shlex.split(strPwUserCmd) processUser = subprocess.Popen(listCmdArgs,stdin=objTempPassFile.fileno(),stdout=subprocess.PIPE,stderr=subprocess.PIPE) and listCmdArgs = shlex.split(strPwUserCmd) processUser = subprocess.Popen(listCmdArgs,stdin=objTempPassFile,stdout=subprocess.PIPE,stderr=subprocess.PIPE) where the objTempPassFile is a file object I've written the password too, done a seek(0) to reset it and left it open. like: objTempPassFile = open(strTempDir + 'foobar.txt', 'w+') objTempPassFile.write(strTempPass) objTempPassFile.seek(0) I realize this is more of a "Python" question, but figured someone on here might be able to get me straightened out. thanks. henrik -- Henrik Hudson lists@rhavenn.net ----------------------------------------- "God, root, what is difference?" Pitr; UF
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150327010330.GA70222>