1.用python调用python脚本

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

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

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

运行结果:

[python@master2 while]$ python a.py
hello world this count is:
this count is:
this count is:
this count is:
this count is:
this count is:
this count is:
this count is:
Good Bye

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

#!/usr/local/bin/python3.
import time
import os count =
n = os.system('sh b.sh')
while True:
count = count +
if count == :
print('this count is:',count)
break
else:
time.sleep()
print('this count is:',count) print('Good Bye')

shell脚本如下:

#!/bin/sh
echo "hello world"

运行结果:

[python@master2 while]$ python a.py
hello world
this count is:
this count is:
this count is:
this count is:
this count is:
this count is:
this count is:
this count is:
Good Bye

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

#!/usr/local/bin/python3.
import time
import os count =
n = os.system('sh b.sh')
while True:
count = count +
if count == :
print('this count is:',count)
break
else:
time.sleep()
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:
this count is:
this count is:
this count is:
this count is:
this count is:
this count is:
this count is:
Good Bye

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

python调用其他脚本的更多相关文章

  1. Python 调用 Shell脚本的方法

    Python 调用 Shell脚本的方法 1.os模块的popen方法 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出. > ...

  2. python调用shell脚本时需要切换目录

    最近遇到了一个问题,就是python代码调用shell脚本时,发现输入输出的文件,总是和自己预想的有偏差,但是单独在linux下执行命令的时候,却没有错误.后来发现是相对路径的问题,因为执行pytho ...

  3. python调用matlab脚本

    在MATLAB和Python之间建个接口,从Python中调用MATLAB脚本或者是MATLAB的函数.内容不是很难,毕竟现成的接口已经有了,在这儿记录一下API使用的一些事项. 注:本篇使用的是MA ...

  4. 3种python调用其他脚本的方法,你还知道其他的方法吗?

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

  5. python调用shell脚本

    # coding=utf-8   //设置文本格式import os            //导入os方法print('hello')n=os.system('/home/csliyb/kjqy_x ...

  6. 精华 selenium_webdriver(python)调用js脚本

    #coding=utf-8 from selenium import webdriver import time driver = webdriver.Firefox() driver.get(&qu ...

  7. python 调用java脚本的加密(没试过,先记录在此)

    http://lemfix.com/topics/344 前言 自动化测试应用越来越多了,尤其是接口自动化测试. 在接口测试数据传递方面,很多公司都会选择对请求数据进行加密处理. 而目前为主,大部分公 ...

  8. 使用python调用其他脚本

    cmd = '<command line string>' print(cmd) p = subprocess.Popen(args=cmd, shell=True, stdout=sub ...

  9. python模拟鼠标键盘操作 GhostMouse tinytask 调用外部脚本或程序 autopy右键另存为

    0.关键实现:程序窗口前置 python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过pyauto实现右键菜单和另存为操作 1.参考 aut ...

随机推荐

  1. 01 MySQL之数据库基本操作

    01-介绍 数据库(DataBase,DB)是一个长期存储在计算机内的.有组织的.有共享的.统一管理的数据集合. 02-基本操作 2.1 创建数据库 # 查看当前所有的数据库 show databas ...

  2. 数据中心网络架构的问题与演进 — NFV

    目录 文章目录 目录 前文列表 前言 NFV NFV 的最终目标 NFV 的抽象框架 基础架构层与虚拟基础设施管理层 资源管理与业务流程编排层 OSS 层 SDN 控制层 NFV 的生态合作 NFV ...

  3. java代码实现简体繁体转换

    汉字分为简体和繁体字,这是众所周知的,虽然繁体字中国大陆这边用的并不会太多,但时不时的还是会使用到.那么,如何做到简体字和繁体字的转换呢?其实很简单,这里附上一个java版本的简繁体转换,用网上找的接 ...

  4. jQuery上传文件显示进度条

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script sr ...

  5. [转]Java Jacob操作Excel

    Jacob项目:https://sourceforge.net/projects/jacob-project/ 转自:https://blog.csdn.net/ZY_extreme/article/ ...

  6. 【C# in depth 第三版】温故而知新(1) (转)

    声明 本文欢迎转载,原文地址:http://www.cnblogs.com/DjlNet/p/7192354.html 前言 关于这本书(<深入理解C# 第三版>)的详细情况以及好坏,自行 ...

  7. SAP JCO3配置

    windows 环境设置 1.sapjco3.dll 需要与 sapjco3.jar 在同一目录 2.设置系统环境变量,将sapjco3所在目录加入系统环境变量 例如: 新建环境变量 变量名: JAV ...

  8. 封装Button ,封装UITableView,封装UICollectionView

    ---恢复内容开始--- 封装Button ,封装UITableView,封装UICollectionView: 1.实现Button的创建和点击事件不用分开操作处理; 2.实现UITableView ...

  9. redis报错解决

    1.Connecting to node 127.0.0.17000 [ERR] Sorry, can't connect to node 192.168.1.917000 redis集群:Conne ...

  10. centos7.2 mysql tar.gz 搭建 (亲测成功)

    1.安装依赖:yum -y install libaioyum search libaio 2.卸载系统自带的Mariadb数据库:rpm -qa | grep mariadbrpm -e --nod ...