pass string to a os prompt

Peter Hansen peter at
Fri Feb 20 21:00:09 CET 2004

Bart Nessux wrote:
> I'm writing a script that does some basic pre-configuration for our new
> Macs (OSX 10.3.2). I'm trying to enable the root account automatically
> with the script, but I don't know how to pass stings to the shell when
> it stops and awaits input. For example,
> os.popen('/usr/bin/sudo passwd root')

Try something like this:

  os.system('echo newpass | /usr/bin/sudo passwd --stdin root')

(This works without the sudo while I was logged in as root, but I didn't 
try it using sudo.)


More information about the Python-list mailing list