python执行shell命令

 2023-09-05 阅读 14 评论 0

摘要:2019独角兽企业重金招聘Python工程师标准>>> 假定shellString为将要通过python执行的shell命令,3种方式如下 import osstatus = os.system(shellString),只输出shell返回值import osoutput = os.popen(shellString),只输出shell输出值import command

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

假定shellString为将要通过python执行的shell命令,3种方式如下

  1. import os

    status = os.system(shellString),只输出shell返回值

  2. import os

    output = os.popen(shellString),只输出shell输出值

  3. import commands

    commands官方给的解释(help(commands))为通过os.popen()执行shell命令并返回状态码

    status = commands.getstatus(shellString),只输出shell返回值

    output = commands.getoutput(shellString),只输出shell输出值

    (status,output) = commands.getstatusoutput(shell),输出shell的返回值和输出值

转载于:https://my.oschina.net/vnlyzhang/blog/355887

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/1620.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息