Python 启动新终端并运行命令

Python 启动新终端并运行命令,python,postgresql,ubuntu,Python,Postgresql,Ubuntu,我正在写一个应用程序,管理员必须输入他的用户名和密码。通过这样做,一个终端在ubuntu中启动,并具有以下命令: adduser admin passwd admin su - postgres psql postgres # run postgres ccommands ie grant all privileges with a password for the user 我不希望用户键入任何内容,因为表单提供了postgres数据库的名称以及postgres的用户名和密码 用户只需输入其

我正在写一个应用程序,管理员必须输入他的用户名和密码。通过这样做,一个终端在ubuntu中启动,并具有以下命令:

adduser admin
passwd admin
su - postgres
psql postgres
# run postgres ccommands ie grant all privileges with a password for the user
我不希望用户键入任何内容,因为表单提供了postgres数据库的名称以及postgres的用户名和密码

用户只需输入其密码和管理员系统密码


谢谢

如果您真的想启动终端,您需要将命令列表传递给终端生成的shell。其语法在某种程度上取决于所使用的终端

对于
gnome终端
,您需要:

gnome-terminal -e '... command ...'
e、 g

我建议使用
sudo
而不是
su
,如上所示


&
意味着“只有在前一个命令返回零(成功)时才运行下一个命令”

您是要求我们为您编写程序,还是您不理解问题的某个特定部分?我知道我可以用pythi-python:os.system(“gnome-terminal-e'bash-c\“sudo adduser tom\”)编写这个命令。我可以写多行吗?我只想要一段代码,在那里我可以启动ubuntu终端并自动运行某些命令。。准确地说不止一个。。我只能运行一个命令,但我希望在终端窗口中运行许多命令OGO-编辑您的问题,以添加您确实拥有的代码,以及您拥有的确切问题(并在此处的注释中描述)。这将帮助你得到一些答案。我会添加编辑,希望它会是你想要的。
gnome-terminal -e 'sh -c "adduser admin && passwd admin && sudo -u postgres psql"'