From owner-freebsd-questions@FreeBSD.ORG Fri Mar 27 01:10:57 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7463D1FE for ; Fri, 27 Mar 2015 01:10:57 +0000 (UTC) Received: from smtp68.ord1c.emailsrvr.com (smtp68.ord1c.emailsrvr.com [108.166.43.68]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4BB4E876 for ; Fri, 27 Mar 2015 01:10:57 +0000 (UTC) Received: from smtp9.relay.ord1c.emailsrvr.com (localhost.localdomain [127.0.0.1]) by smtp9.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id 797163801BC for ; Thu, 26 Mar 2015 21:03:32 -0400 (EDT) Received: by smtp9.relay.ord1c.emailsrvr.com (Authenticated sender: rhavenn-AT-rhavenn.net) with ESMTPSA id 203703801AC for ; Thu, 26 Mar 2015 21:03:32 -0400 (EDT) X-Sender-Id: rhavenn@rhavenn.net Received: from vash.rhavenn.local ([UNAVAILABLE]. [209.112.171.194]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:25 (trex/5.4.2); Fri, 27 Mar 2015 01:03:32 GMT Received: from localhost (vash.rhavenn.local [local]); by vash.rhavenn.local (OpenSMTPD) with ESMTPA id 17b7cf61; for ; Thu, 26 Mar 2015 17:03:30 -0800 (AKDT) Date: Thu, 26 Mar 2015 17:03:30 -0800 From: Henrik Hudson To: freebsd-questions@freebsd.org Subject: pw -h file descriptor flag and python scripts... Message-ID: <20150327010330.GA70222@vash.rhavenn.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Mar 2015 01:10:57 -0000 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