python调用可执行文件_如何从Python脚本调用可执行文件?
I need to execute this script from my Python script.
Is it possible? The script generate some outputs with some files being written. How do I access these files? I have tried with subprocess call function but without success.
fx@fx-ubuntu:~/Documents/projects/foo$ bin/bar -c somefile.xml -d text.txt -r aString -f anotherString >output
The application "bar" also references to some libraries, it also create the file "bar.xml" besides the output. How do I get access to these files? Just by using open()?
Thank you,
Edit:
The error from Python runtime is only this line.
$ python foo.py
bin/bar: bin/bar: cannot execute binary file
解决方案
For executing the external program, do this:
import subprocess
args = ("bin/bar", "-c", "somefile.xml", "-d", "text.txt", "-r", "aString", "-f", "anotherString")
#Or just:
#args = "bin/bar -c somefile.xml -d text.txt -r aString -f anotherString".split()
popen = subprocess.Popen(args, stdout=subprocess.PIPE)
popen.wait()
output = popen.stdout.read()
print output
And yes, assuming your bin/bar program wrote some other assorted files to disk, you can open them as normal with open("path/to/output/file.txt"). Note that you don't need to rely on a subshell to redirect the output to a file on disk named "output" if you don't want to. I'm showing here how to directly read the output into your python program without going to disk in between.
python调用可执行文件_如何从Python脚本调用可执行文件?相关推荐
- python 调用控制台_如何使用Python的交互控制台
简介 Python的交互控制台(也叫做Python解释器,或是Python Shell)为程序员提供了"运行指令"和"不创建文件测试测试代码"的快速途径. 交互 ...
- python引流_怎样用python写引流脚本
Python是一门非常适合处理数据和自动化完成重复性工作的编程语言,我们在用数据训练机器学习模型之前,通常都需要对数据进行预处理,而Python就非常适合完成这项工作,比如需要重新调整几十万张图像的尺 ...
- python 函数调用列表_在项目列表上调用一个函数的最简洁方法 - python
在python 2中,我使用map将函数应用于多个项目,例如,删除所有与模式匹配的项目: map(os.remove,glob.glob("*.pyc")) 当然我忽略了os.re ...
- c++调用python接口打包_在QT C++中调用 Python并将软件打包发布(裸机可运行)
为了提高工作效率,需要一个可以自动生成多份相关联的word文档免去繁琐复制粘贴工作的软件.最后选定使用QT C++做界面和主要逻辑程序设计,对word的操作使用python写好对应的函数,然后在QT中 ...
- python如何调用字典_如何访问python字典里的值?(实例解析)
今天这篇文章中我们来了解一下python之中的字典,在这文章之中我会对python字典访问进行说明,以及python使用.访问字典的实例分析.好了废话不多说,我们开始进入文章吧. 访问字典里面的值 把 ...
- python求加速度_如何利用Python 为自然语言处理加速度
自去年发布 Python 的指代消解包(coreference resolution package)之后,很多用户开始用它来构建许多应用程序,而这些应用与我们最初的对话应用完全不同. 利用 spaC ...
- python优化网站_[练习] 用PYTHON来优化网站中的图片
我到公司以来,第一次加班,哇,加一晚上加一上午,现在还没下班的迹象,555,困. 对于网站中的一些关键的页面,多重缓存.静态化.程序代码优化--之外,为了提高用户打开页面的速度,图片是必须要优化的. ...
- python编写函数_如何用Python编写自己喜欢的R函数
python编写函数 数据科学和机器学习的伟大现代斗争之一是" Python vs. R". 毫无疑问,近年来两者都已经取得了巨大的发展,成为数据科学,预测分析和机器学习的顶级编程 ...
- python 多核并行计算_手把手 | 嫌Python太慢?并行运算Process Pools三行代码给你4倍提速!...
大数据文摘作品,转载要求见文末 作者 | Adam Geitgey 编译 | 元元.Lisa.Saint.Aileen 原文链接 | https://medium.com/@ageitgey/quic ...
最新文章
- c语言函数指针的理解与使用(学习)
- Asp.net MVC3 一语道破
- sp MySQL 导入_mysql数据导入redis
- 《炉石传说》的退环境机制失败在哪
- WPF--动态添加控件、访问控件
- 博客搬家到github啦
- gprMax 正演模拟中Ex、Ey、Ez三个分量之间的关系分析
- spring cloud构建互联网分布式微服务云平台-服务注册与发现
- python解释器的提示符是shell嘛_windows python3.2 shell环境(python叫做解释器)
- 高中数学解析几何求轨迹常用的六种解题方法(实用干货)
- 内容播放colorbox
- 华大基因首席运营官张凌离职
- MMORPG开发入门
- php返回503,网站返回503是什么意思
- SDK接入(之Android Google Play内支付(in-app Billing)接入的细节
- 2019最新微信墙微信上墙微信弹幕婚庆会议大屏幕3D签到抽奖摇一摇微信上墙
- AppiumLibrary 时间控件的选择
- 利用Django实现一个博客(附全部源码)
- ICPC 沈阳M - United in Stormwind SOSDP+FWT+容斥
- 免费Linux CAD应用软件
热门文章
- C#之Enum中的Flag
- [SoapUI] context.expand 和 groovyUtils.getXmlHolder 有什么不一样
- Python List Comprehension
- c++对象模型大总结:第1-4章、对象初探与构造函数
- SharePoint 2010中增强的错误跟踪机制
- RecycleView的左滑实现
- Git(14)-- Git分支-- 分支管理
- Ubuntu18.04安装微信(方式二)
- springboot之websocket集成
- PyTorch 中自定义数据集的读取方法