当前位置: 首页 > >

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

发布时间:

试试这个: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 = rC:UsersyouDesktopmy_file.exe # example


your_module_address = rC:UsersyouDesktop est.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], stdout=PIPE, stderr=PIPE, shell=True)


print(stdout, stderr)


else:


print("Invalid Input")


另一种方式:


^{pr2}$


第三种方法(在Windows上,安装pywin32包):import win32com.client


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


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


your_exe_file_address = rC:UsersyouDesktopmy_file.exe # example


your_module_address = rC:UsersyouDesktop est.m # example


your_command = "call"


last_shell = your_exe_file_address + " " + your_command + " " + your_module_address


shell = win32com.client.Dispatch("WScript.Shell")


shell.Run(last_shell)


else:


print("Invalid Input")


第四种方式:


将命令保存在.bat文件中,如下所示:"C:UsersyouDesktopmy_file.exe" call "C:UsersyouDesktop est.m"


然后尝试启动此bat文件并获取其输出:import os


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


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


your_bat_file_address = rC:UsersyouDesktopmy_bat.bat # example


os.startfile(your_bat_file_address)


else:


print("Invalid Input")


祝你好运。。。在







相关资源:python运行exe



友情链接: