所以我们有了我们的软件产品,我目前正在研究一种自动化安装的方法。它将完成的方式是:
- 我有一个
config.cfg文件,其中包含有关Apache、用户Tomcat和MySQL's密码以及端口号的所有信息。 - 我
ConfigParser曾经拥有该信息。
安装程序脚本是迭代的:您可以像执行它一样执行它sudo foo.run,它会提示命令行,因此进行安装的人可以输入上述输入。例如:
Apache user: **[foo]**
Apache password: **[bar]**
输入该信息后,安装程序将实际安装该产品。但是,我想自动化整个过程,包括使用Python.
到目前为止,我带着这个:
1 from subprocess import Popen, call, PIPE, STDOUT
2 import errno
3 import os
4 fname = "/home/ec2-user/foo.run"
5 os.chmod(fname, 0777) # make it executable
6 cmd = "sudo %s" % fname
7 print cmd
9 p = Popen(cmd, stdin=PIPE, stdout=PIPE,
10 stderr=STDOUT, shell=True)
11 # now is actually the missing part ... reading from the stdout and writing
12 # to stdin ... how could I accomplish that? Is there a easier way of doing it?
13 p.wait()
所以我在设计stdin/stdout部分的工作方式时遇到了一些麻烦......我需要一个while循环来读取它,直到它stdout为空,然后我将注入包含在ConfigParser. 有人可以举个例子吗?还有其他更简单的方法吗?我愿意接受任何建议……对我来说,第一步可能是从 python 进行手动安装程序,Python's p.stdin.write()用于将信息提供给安装程序。