问题描述
我正在尝试通过 wscript 运行具有 anaconda 环境(或只是具有某些版本的 python)的 python 程序,该程序将被放置在批处理文件中,因此我只需双击批处理文件即可运行该程序。
这是代码
Set WinScriptHost = WScript.CreateObject("WScript.Shell")
WinScript.Run "C:\anaconda3\envs\card_player\python.exe C:\projects\card_player\auto_play.py"
Set WinScriptHost = nothing
我不知道为什么它不起作用,同时,运行 python 是完美的
python c:\projects\card_player\auto_play.py
在控制台中。
我做错了什么? 单击批处理文件后,控制台弹出并立即消失...
解决方法
将 WinScript.Run "C:\anaconda3\envs\card_player\python.exe C:\projects\card_player\auto_play.py" 替换为以下行:
WinScriptHost.Run("C:\anaconda3\envs\card_player\python.exe C:\projects\card_player\auto_play.py")