python打开exe文件并传递信息_打开一个.exe文件并用Python为其提供输入参数

本文介绍了四种方法使用Python打开并传递信息给.exe文件。包括使用`subprocess`模块的Popen、check_output、check_call和call方法,通过win32com.client模块的Dispatch方法,创建批处理文件并通过os.startfile执行,以及直接调用批处理文件来运行.exe程序。
摘要由CSDN通过智能技术生成

试试这个:from subprocess import Popen, check_output, check_call, PIPE, call

get_input = input("What Should I do?")

if get_input.strip().lower() == "run":

your_exe_file_address = r'"C:\Users\you\Desktop\my_file.exe"' # example

your_module_address = r'"C:\Users\you\Desktop\test.m"' # example

your_command = "call"

process = Popen([your_exe_file_address, your_command, your_module_address], stdout=PIPE, stderr=PIPE, shell=True)

stdout, stderr = process.communicate()

# < Other Ways >

# process = check_output([your_exe_file_address, your_command, your_module_address])

# process = check_call([your_exe_file_address, your_command, your_module_address], shell=True)

# process = call([your_exe_file_address, your_command, your_module_address], s

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值