方法一:os.popen#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys# 使用 mkdir 命令a = lsb = os.popen(a,w,1)print b方法二:os.system#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys arg0=...

方法一:os.popen
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 使用 mkdir 命令 a = 'ls' b = os.popen(a,'w',1) print b
方法二:os.system
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys arg0="121.429015" arg1="31.245255" os.system('sh trans.sh '+arg0+' '+arg1)
其中trans.sh代码:
echo $1 $2
方法三:subprocess
import subprocess returnCode = subprocess.call('pwd') print returnCode
方法四:commands
import commands result=commands.getoutput('pwd') result1=commands.getstatusoutput('pwd') print result print result1
沃梦达教程
本文标题为:Linux系统下python代码运行shell命令的方法


基础教程推荐
猜你喜欢
- centos系统 anaconda3(python3)安装pygrib 2023-09-04
- Centos7下安装python环境 2023-09-04
- Python基础学习之函数和代码复用详解 2022-09-02
- python的环境conda简介 2022-10-20
- 基于Python实现股票数据分析的可视化 2023-08-04
- Python 中 Elias Delta 编码详情 2023-08-08
- Python爬取当网书籍数据并数据可视化展示 2023-08-11
- CentOS 7.5 安装 Python3.7 2023-09-03
- ubuntu 18 python3.6 的安装与 python2的版本切换 2023-09-03
- 四步教你学会打包一个新的Python模块 2022-10-20