Mongo 通过操作系统shell 操作数据库方法 --eval
方便使用脚本
mongo DBname --eval 'db.collection.count()'
Python调用系统命令的方法
os.system(),os.popen(),commands
os.system('cat /proc/cpuinfo')
但是这样是无法获得到输出和返回值的
output= os.popen('cat /proc/cpuinfo')
print output.read()
通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出。
commands.getstatusoutput() 一个方法就可以获得到返回值和输出,非常好用。
(status, output)= commands.getstatusoutput('cat /proc/cpuinfo')