pw -h file descriptor flag and python scripts...

Henrik Hudson lists at rhavenn.net
Fri Mar 27 01:10:57 UTC 2015


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 at rhavenn.net
-----------------------------------------
"God, root, what is difference?" Pitr; UF 



More information about the freebsd-questions mailing list