微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过 Python 将参数传递给可执行文件

如何解决通过 Python 将参数传递给可执行文件

我试图让我的用户从可执行文件文件夹中选择一个可执行文件。我的目的是将参数“/service”添加到该可执行文件中,然后让它运行。

目前用户正在将可执行文件复制到桌面,创建快捷方式,然后手动将 /service 添加到快捷方式作为解决方案。肯定有更好的方法

有人可以看看这段代码并告诉我我可能遗漏了什么吗?

import ctypes
import os
import tkinter as tk
from tkinter import filedialog

#Hide the command window... use 6 instead of 0 for simply minimizing
ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(),0 )

#create the initial message window for the user
def MBox(title,text,style):
    return ctypes.windll.user32.MessageBoxW(0,title,style)
MBox('Service Tools Installer','CLevertexthere',1)
root = tk.Tk()
root.withdraw()

#have the user select the file they want to use...
root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("exe files","*.exe"),("all files","*.*")))

#Now to run the executable with the correct pass attached...
os.startfile (root.filename + "/service")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。