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
', 'manage_deploy.sh
', 'mysql_setup.sh
', 'python_manage_deploy.sh
', 'setup.sh
']
(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 line in p.stdout.readlines():
print line,
retval = p.wait()
(4) commands
:getoutput getstatusoutput
>>> import commands
>>> commands.getoutput('ls *.sh')
'install_zabbix.sh
manage_deploy.sh
mysql_setup.sh
python_manage_deploy.sh
setup.sh'
>>> commands.getstatusoutput('ls *.sh')
(0, 'install_zabbix.sh
manage_deploy.sh
mysql_setup.sh
python_manage_deploy.sh
setup.sh')
: , subprocess, os.popen 。