1
我用發送密碼與使用子進程卡在一個死衚衕,我不知道什麼是錯的。我會很感激任何提示。Python:使用子進程發送postgres密碼
我的代碼:
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)
一切都沒問題,但我希望可以捕捉到用戶輸入的密碼,並在未來,我想存儲在配置文件中的密碼。那可能嗎?