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

Henrik Hudson lists at
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 =
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 =


listCmdArgs = shlex.split(strPwUserCmd)
processUser =

where the objTempPassFile is a file object I've written the password
too, done a seek(0) to reset it and left it open.

objTempPassFile = open(strTempDir + 'foobar.txt', 'w+')

I realize this is more of a "Python" question, but figured someone
on here might be able to get me straightened out.



Henrik Hudson
lists at
"God, root, what is difference?" Pitr; UF 

More information about the freebsd-questions mailing list