方法一: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命令的方法


猜你喜欢
- windows安装python2.7.12和pycharm2018教程 2023-09-03
- python线程池ThreadPoolExecutor与进程池ProcessPoolExecutor 2023-09-04
- 在centos6.4下安装python3.5 2023-09-04
- Python之路-Python中的线程与进程 2023-09-04
- Python实现将DNA序列存储为tfr文件并读取流程介绍 2022-10-20
- CentOS7 安装 Python3.6 2023-09-04
- python中defaultdict用法实例详解 2022-10-20
- Python Pandas如何获取和修改任意位置的值(at,iat,loc,iloc) 2023-08-04
- python中列表添加元素的几种方式(+、append()、ext 2022-09-02
- Python 保存数据的方法(4种方法) 2023-09-04