1. os.system()
- system(command) -> exit_status
-
- Execute the command (a string) in a subshell.
-
-
- # 仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息..
- >>> os.system('ls') #如果再命令行下执行,结果直接打印出来
- 04101419778.CHM bash document media py-django video
- 11.wmv books downloads Pictures python
- all-20061022 Desktop Examples project tools
2.os.popen()
- popen(command [, mode='r' [, bufsize]]) -> pipe
-
- Open a pipe to/from a command returning a file object.
-
- # 此种方法不但执行命令还返回执行后的信息对象
- >>>tmp = os.popen('ls *.py').readlines()
-
- >>>tmp
- Out[21]:
- ['dump_db_pickle.py\n',
- 'dump_db_pickle_recs.py\n',
- 'dump_db_shelve.py\n',
- 'initdata.py\n',
- '__init__.py\n',
- 'make_db_pickle.py\n',
- 'make_db_pickle_recs.py\n',
- 'make_db_shelve.py\n',
- 'peopleinteract_query.py\n',
- 'reader.py\n',
- 'testargv.py\n',
- 'teststreams.py\n',
- 'update_db_pickle.py\n',
- 'writer.py\n']
将返回的结果赋于一变量,便于程序的处理.
这个是比较有用的。我需要去探测MYSQL的状态最好是能够将返回的信息写到文件中去的!
阅读(1403) | 评论(0) | 转发(0) |