python - 如何将 .txt 文件 arg 传递给 exe 应用程序?
问题描述
我需要将 .txt 文件与 .exe 应用程序结合起来。当我在 .exe 应用程序上移动 .txt 时,此过程在我的桌面上正常工作。我可以用python做到这一点吗?
解决方案
是的,你只是这样做
from subprocess import call
call(["that.exe", "that.txt"])
或者
import os
os.system("that.exe that.txt")
编辑:
也许你需要打电话cmd \c
来运行exe?
from subprocess import call
call(["cmd", "/c", "that.exe", "that.txt"])
或者
import os
os.system("cmd /c that.exe that.txt")
编辑:
如果您想在调用进程后将击键发送到进程,您可以使用 subprocess 来获取可以跟进的对象。
import subprocess
proc = subprocess.Popen(["cmd", "/c", "that.exe", "that.txt"], shell=True)
proc.communicate(input=b'\n')
最终编辑:
你可能需要使用 stdin=subprocess.PIPE ......
import subprocess
proc = subprocess.Popen(["cmd", "/c", "that.exe", "that.txt"] ,stdin=subprocess.PIPE)
proc.communicate(input=b'\n')
推荐阅读
- function - 状态:503 服务不可用 Azure 功能
- amazon-web-services - 如何在 Cost Explorer 中跟踪 CreateVolume-Gp2 API 调用?
- jquery - jquery ajax() 后退按钮不会改变内容
- openmdao - 在使用 Openmdao 的 Openaerostruct 中运行示例
- android - RECEIVE_BOOT_COMPLETED - 什么时候触发?
- visual-studio-2017 - VS2017专业版有“依赖”菜单吗?
- javascript - Chart.js 可变数据我怎样才能使这项工作?
- go - 为什么在我使用库 golang go-mssqldb 连接到 sql server 后,它会打印
? - java - 如何修复选择今天的日期,从日期中减去几天并将日期添加到 EditText
- java - 为什么要重写接口方法?