args参数由字符串形式提供且有多个命令参数时,需要提供 res = subprocess.call('ls')print 'res:', resres = subprocess.call('ls -l', shell = True)print 'res:', res
import subprocesstry:res = subprocess.check_call(['ls', '?'])print 'res:', resexcept subprocess.CalledProcessError as exc:print 'returncode:', exc.returncodeprint 'cmd:', exc.cmdprint 'output:', exc.output 输出: |
|
来自: LibraryPKU > 《Python》