【发布时间】:2014-10-01 15:10:28
【问题描述】:
我在使用子进程发送密码时陷入了死胡同,我不知道出了什么问题。如有任何提示,我将不胜感激。
我的代码:
os.system("sudo -u postgres -h " + db_host + " psql postgres -c \"\password\" ")
os.system("sudo -u postgres -h " + db_host + " createuser " + db_user);
print bcolors.WARNING, "Please enter your password for : " + db_user, bcolors.ENDC
str = "sudo -u postgres -h " + db_host + " psql postgres -c \"\password " + db_user + "\""
# os.system(str)
p = subprocess.Popen(['sudo','-u', 'postgres', '-h', db_host, 'psql', 'postgres', "-c", "\password", db_user],stdin=subprocess.PIPE, shell=False)
p.communicate(raw_input("Please give me a password!")
使用os.system(str) 时一切正常,但我想从用户那里获取输入的密码,并且将来我想将密码存储在配置文件中。这可能吗?
【问题讨论】:
标签: python postgresql python-2.7