1.用python调用python脚本

#!/usr/local/bin/python3.7
import time
import oscount = 0
str = ('python b.py')
result1 = os.system(str)
print(result1)
while True:
count = count + 1
if count == 8:
print('this count is:',count)
break
else:
time.sleep(1)
print('this count is:',count)print('Good Bye')

另外一个python脚本b.py如下:

#!/usr/local/bin/python3.7
print('hello world')
1
2

运行结果:

[python@master2 while]$ python a.py
hello world
this count is: 1
this count is: 2
this count is: 3
this count is: 4
this count is: 5
this count is: 6
this count is: 7
this count is: 8
Good Bye

2.python调用shell方法os.system()

'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:778463939
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
#!/usr/local/bin/python3.7
import time
import oscount = 0
n = os.system('sh b.sh')
while True:
count = count + 1
if count == 8:
print('this count is:',count)
break
else:
time.sleep(1)
print('this count is:',count)print('Good Bye')

shell脚本如下:

#!/bin/sh
echo "hello world"
1
2
echo “hello world”

运行结果:

[python@master2 while]$ python a.py
hello world
this count is: 1
this count is: 2
this count is: 3
this count is: 4
this count is: 5
this count is: 6
this count is: 7
this count is: 8
Good Bye

3.python调用shell方法os.popen()

'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:778463939
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
#!/usr/local/bin/python3.7
import time
import oscount = 0
n = os.system('sh b.sh')
while True:
count = count + 1
if count == 8:
print('this count is:',count)
break
else:
time.sleep(1)
print('this count is:',count)print('Good Bye')

运行结果:

[python@master2 while]$ python a.py
<os._wrap_close object at 0x7f7f89377940>
['hello world\n']
this count is: 1
this count is: 2
this count is: 3
this count is: 4
this count is: 5
this count is: 6
this count is: 7
this count is: 8
Good Bye

os.system.popen()这个方法会打开一个管道,返回结果是一个连接管道的文件对象,该文件对象的操作方法同open(),可以从该文件对象中读取返回结果。如果执行成功,不会返回状态码,如果执行失败,则会将错误信息输出到stdout,并返回一个空字符串。这里官方也表示subprocess模块已经实现了更为强大的subprocess.Popen()方法。

3种python调用其他脚本的方法,你还知道其他的方法吗?相关推荐

  1. python调用脚本_3种python调用其他脚本的方法

    1.用python调用python脚本 #!/usr/local/bin/python3.7 import time import os count = 0 str = ('python b.py') ...

  2. Python语言学习:利用python语言实现调用内部命令(python调用Shell脚本)—命令提示符cmd的几种方法

    Python语言学习:利用python语言实现调用内部命令(python调用Shell脚本)-命令提示符cmd的几种方法 目录 利用python语言实现调用内部命令-命令提示符cmd的几种方法 T1. ...

  3. Python 调用shell脚本

    python调用Shell脚本,有两种方法:os.system(cmd)或os.popen(cmd),前者返回值是脚本的退出状态码,后者的返回值是脚本执行过程中的输出内容. 实际使用时视需求情况而选择 ...

  4. python调用Shell脚本:os.system(cmd)或os.popen(cmd),

    python调用Shell脚本,有两种方法:os.system(cmd)或os.popen(cmd),前者返回值是脚本的退出状态码,后者的返回值是脚本执行过程中的输出内容.实际使用时视需求情况而选择. ...

  5. 简单python脚本实例-简单了解python调用其他脚本方法实例

    1.用python调用python脚本 #!/usr/local/bin/python3.7 import time import os count = 0 str = ('python b.py') ...

  6. python调用shell脚本的参数_使用python执行shell脚本 并动态传参 及subprocess的使用详解

    最近工作需求中 有遇到这个情况 在web端获取配置文件内容 及 往shell 脚本中动态传入参数 执行shell脚本这个有多种方法 最后还是选择了subprocess这个python标准库 subpr ...

  7. python 调用shell 不阻塞_遇到问题---python调用shell脚本时subprocess.check_call不阻塞

    遇到的问题 使用命令 subprocess.check_call(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) ...

  8. python调用vbs脚本_使用python创建的参数执行vbs文件

    我想一次将几十个excel表格转换成csv文件.我有一个正在工作的.vbs文件来进行转换,我想在python代码的帮助下在不同的工作表上执行这个.vbs文件.我有以下两个版本的python代码: 版本 ...

  9. java执行shell命令权限不够_Java调用shell脚本解决传参和权限问题的方法|chu

    1. java 执行shell java 通过 Runtime.getRuntime().exec() 方法执行 shell 的命令或 脚本,exec()方法的参数可以是脚本的路径也可以是直接的 sh ...

最新文章

  1. Makefile完全解析PART5.使用变量
  2. RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2- “Tab”标签新增可“最大化”显示功能...
  3. UA MATH566 统计理论8 置信区间简介
  4. docker WARNING: bridge-nf-call-iptables is disabled 处理
  5. 李笑来 css,李笑来都想投资千万美金的ACSS通证即将强势登陆奇点交易所
  6. ubuntu查看默认python版本_ubuntu中修改默认Python版本号
  7. php5.2 zengd,大对杀狗狗再犯低级错误 ZEN狂输200目笑翻棋友
  8. 大数据之-Hadoop完全分布式_集群文件存储路径说明_完全分布式集群测试---大数据之hadoop工作笔记0038
  9. 小程序----API
  10. android 平板键盘布局,android 4.1 平板连接USB键盘,默认键盘布局
  11. 记一次蛋疼的App 调用su 之旅
  12. 该网页无法正常运作127.0.0.1 将您重定向的次数过多。 尝试清除 Cookie. ERR_TOO_MANY_REDIRECTS---关于flask遇到的此状况的解决办法
  13. 透明度轮播图和滚动轮播图
  14. 《三国演义》统帅对比
  15. Oracle 错误总结及问题解决 ORA
  16. 学会这些思维模型,窥见查理·芒格的致胜秘笈(二)
  17. jquery 编码解码
  18. Meta Connect汇总:Quest Pro发布,主打生产力场景
  19. C语言逗号表达式赋值、野指针成因、用户标识符、字符串赋值的几个概念
  20. Jetpack(五)—— Navigation

热门文章

  1. js经典试题之数据类型
  2. 企业托管云模式 浪潮ERP签约山东医药
  3. 使用FMDB多线程訪问数据库,及database is locked的问题
  4. SettingsPLSQLDeveloper
  5. Oracle 常用语句
  6. 【实用】表维护视图SM30增加自定义按钮的实现
  7. 【转】SAP Cloud Platform平台下,ABAP人员的出路在哪里
  8. SAP已发票校验采购订单退货 - 特殊业务
  9. 【PP操作手册】运行MRP产生计划订单
  10. 【力荐】Select查询语句中LIKE关键词的优化方法分析