Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 python中怎么运行shell脚本

python中怎么运行shell脚本

发布时间:2020-10-17   编辑:www.jquerycn.cn
jquery中文网为您提供python中怎么运行shell脚本等资源,欢迎您收藏本站,我们将为您提供最新的python中怎么运行shell脚本资源

python中怎么运行shell脚本?

system()

其中最后一个0是这个命令的返回值,为0表示命令执行成功。使用system无法将执行的结果保存起来。

c9bdf13df1d3b5bf01f53f8800f78fa.png

popen()

获取命令执行的结果,但是没有命令的执行状态,这样可以将获取的结果保存起来放到list中。

cb3b4abe029134d5fb3947a946b1ea1.png

commands

可以很方便的取得命令的输出(包括标准和错误输出)和执行状态位。

commands.getoutput('ls')这个方法只返回执行结果result不返回状态。

3bd009b470147edfeb096547879f19e.png

在python中调用shell脚本

hello.sh

9b642373af6ef84832c261c8fbee63a.png

下面的512是返回的状态码,如果eixt 0时则返回的是0.

6043aba2b9db8fdfe07427ca286a0b8.png

shell脚本使用python脚本的参数

写一个hello.sh脚本,需要传入两个参数:

911facdabe9d1cd8b96bfab909f13cf.png

执行结果如下:

6ee8461a0cd40b6b0612a9a7017b9a6.png

在python脚本中调用shell脚本,并传入参数,注意参数前后要有空格

992579519506b9749925c3edbf877e4.png

执行python脚本

6b5adfb7109b5d009ecc6d0b43eb72d.png

相关推荐:《Python教程》

以上就是python中怎么运行shell脚本的详细内容,更多请关注jquery中文网其它相关文章!

  • 本文原创发布jQuery中文网,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    python中怎么运行shell脚本
    python shell是什么
    linux怎么执行python脚本
    linux如何运行python脚本
    怎么执行python脚本文件
    python怎么下载64位的
    安装python后怎么用
    shell命令行参数用法简介
    python脚本开头怎么写
    python shell脚本怎么打开?

    [关闭]