我在 python 中有一个小脚本,它可以在 Debian 6 (Python 2.6.6) 中使用 apt-get 自动安装一些软件包,如 wget、git。然后脚本安装pip
,然后使用pip
,安装请求和phpserialize。以下是脚本运行时得到的输出:
root@ffVMdeb64:~# python test.py
Reading package lists... Done
mkdir: cannot create directory `/usr/local/src/forpip': File exists
Building dependency tree
Reading state information... Done
git is already the newest version.
wget is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists... Done
Building dependency tree... 50%
Building dependency tree
Reading state information... Done
Requirement already satisfied (use --upgrade to upgrade): phpserialize in /usr/local/lib/python2.6/dist-packages
Cleaning up...
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.6/dist-packages
Cleaning up...
git is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
最后,脚本会从用户那里获取一些输入。但是,该raw_input
语句会在安装过程的输出仍在进行时执行,因此会被覆盖。请注意上面 2 个输出块之间的空格 - 这是raw_input
语句被打印然后被覆盖的地方。
脚本的相关部分如下:
subprocess.call("pip install phpserialize &> /dev/null 2>&1", shell=True)
subprocess.call("pip install requests &> /dev/null 2>&1", shell=True)
subprocess.call("apt-get install git -y &> /dev/null 2>&1", shell=True)
import phpserialize
import requests
from phpserialize import serialize
from phpserialize import unserialize
def checktext():
text = raw_input("\n\n\nEnter your text:")
return text
itext = checktext()
我在 CentOS 6.3 和 6.4 中测试了完全相同的脚本,它按预期工作。我想这与Building dependency tree... 50%
部分有关,apt-get
但我不确定。
我该如何纠正?