匿名用户
1级
2018-11-22 回答
这种情况是使用的方法不正确导致的。
Python中执行系统命令常见的几种方法如下:
1、os.system
例如:
>>> import os >>> os.system('ls') chk_err_log.py CmdTool.log install_log.txt install_zabbix.sh manage_deploy.sh MegaSAS.log
2、os.popen
例如:
>>> import os >>>tmp = os.popen('ls *.sh').readlines() >>>tmp ['install_zabbix.sh\n', 'manage_deploy.sh\n', 'mysql_setup.sh\n', 'python_manage_deploy.sh\n', 'setup.sh\n']
3、使用模块subprocess
使用方法:
>>> import subprocess >>> subprocess.call (["cmd", "arg1", "arg2"],shell=True)
import subprocess p = subprocess.Popen('ls *.sh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print p.stdout.readlines() for l