python调用其他脚本
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调用其他脚本的更多相关文章
- Python 调用 Shell脚本的方法
Python 调用 Shell脚本的方法 1.os模块的popen方法 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出. > ...
- python调用shell脚本时需要切换目录
最近遇到了一个问题,就是python代码调用shell脚本时,发现输入输出的文件,总是和自己预想的有偏差,但是单独在linux下执行命令的时候,却没有错误.后来发现是相对路径的问题,因为执行pytho ...
- python调用matlab脚本
在MATLAB和Python之间建个接口,从Python中调用MATLAB脚本或者是MATLAB的函数.内容不是很难,毕竟现成的接口已经有了,在这儿记录一下API使用的一些事项. 注:本篇使用的是MA ...
- 3种python调用其他脚本的方法,你还知道其他的方法吗?
1.用python调用python脚本 #!/usr/local/bin/python3.7 import time import os count = 0 str = ('python b.py') ...
- python调用shell脚本
# coding=utf-8 //设置文本格式import os //导入os方法print('hello')n=os.system('/home/csliyb/kjqy_x ...
- 精华 selenium_webdriver(python)调用js脚本
#coding=utf-8 from selenium import webdriver import time driver = webdriver.Firefox() driver.get(&qu ...
- python 调用java脚本的加密(没试过,先记录在此)
http://lemfix.com/topics/344 前言 自动化测试应用越来越多了,尤其是接口自动化测试. 在接口测试数据传递方面,很多公司都会选择对请求数据进行加密处理. 而目前为主,大部分公 ...
- 使用python调用其他脚本
cmd = '<command line string>' print(cmd) p = subprocess.Popen(args=cmd, shell=True, stdout=sub ...
- python模拟鼠标键盘操作 GhostMouse tinytask 调用外部脚本或程序 autopy右键另存为
0.关键实现:程序窗口前置 python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过pyauto实现右键菜单和另存为操作 1.参考 aut ...
随机推荐
- selenium死活定位不到元素以及radio单选框点击不生效
今天操作一个单选框浪费太多时间,现在其实很简单得东西,记录一下: 1,问题一,定位不到 如图,使用selenium IDE和xpath helper都试过,无法成功定位到这个单选框,实际上是因为,这个 ...
- python之scrapy初探
1.知识点 """ Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架,我们只需要实现少量的代码,就能够快速的抓取 Scrapy模块: 1.schedul ...
- Linux文档中翻页和搜索关键字
按键 进行工作空格键 向下翻一页[Page Down] 向下翻一页[Page Up] 向上翻一页[Ctrl + U] 向上翻一页[Ctrl + D] 向下翻一页/string 向下搜寻string这个 ...
- Python的一个bug,记录一下
安装报错:E:\webpy-master>python setup.py installTraceback (most recent call last): File "setup.p ...
- 大数据HIve
1. 题目说明 设计题:MySQL数据库A有1000w条数据,完成统计再输入到另外的B表中 A表 test1 0.2,3.5,1,1test1 1.2,2.3,4.56test2 2.1,0.3,9. ...
- JAVA 基础编程练习题16 【程序 16 输入 9*9 表】
16 [程序 16 输入 9*9 表] 题目:输出 9*9 口诀. 程序分析:分行与列考虑,共 9 行 9 列,i 控制行,j 控制列. package cskaoyan; public class ...
- 关于Content-Type中application/x-www-form-urlencoded 和 multipart/form-data的区别及用法
http://blog.csdn.net/soonfly/article/details/52082547 Form的enctype属性表示页面表单数据向服务器传输时的编码方式, 常用有两种:appl ...
- vue项目在(windowServer)nginx上的部署
(一) 本地部署. 1.下载phpStudy (http://phpstudy.php.cn/) 2.安装到自己指定盘根目录的文件夹目录,安装完后会用到. 3.运行phpStusy可能报错,需要下载安 ...
- dfs入门-cogs1640[黑白图像]
题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=vxSmxkeqa [题目描述] 输入一个n×n的黑白图像(1表示黑色,0表示白色),任务 ...
- js放到head中失效的原因与解决方法
1.今天写js碰到一个奇怪的问题,写好的js放到body里面执行,但是放到head中没有任何效果,为什么导致这种原因呢? 看失效代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 ...