python - Python 脚本从命令行运行,从 Excel Shell 停止工作
问题描述
我有一个 Python 脚本,当从远程服务器上的 Excel 执行时,它已成功运行。我最近在本地 PC 上进行了一些测试,更新了 Python 脚本并通过远程桌面进行了测试。从那时起,在远程桌面上,Python 脚本在从命令行执行时工作,但在 Excel 中执行相同的命令时停止工作。代码示例:
'Get file from Gmail using a Python script
vPytnonDir = "C:\Projects\Python"
ChDir vPytnonDir 'Directory where python script resides
Dim wShell As Object
Set wShell = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wShell.Run "cmd.exe /S /C python GetGmail.py", windowStyle, waitOnReturn
当我在命令窗口(在 Python 目录中)运行“cmd.exe /S /C python GetGmail.py”时,该命令有效。我已经刷新了 credentials.json 和 token.json 以拥有对 Gmail 的相同用户访问权限。我在 Python 脚本中暂停了,执行窗口只是闪烁,显然脚本没有暂停。我只用示例代码创建了一个独立的 Excel - 并且有效!这让我发疯(不能说疯了,已经在那里) - 任何帮助将不胜感激。
这已经解决了!当我从本地 PC 完成测试后,我通过“E”驱动器连接到服务器,并且不知何故重置了 Excel 的默认驱动器。代码中的 ChDir 命令根本不起作用,我必须运行 ChDrive("C") 才能让事情恢复正常。
解决方案
推荐阅读
- javascript - 使用本地存储和 Jquery 添加/删除收藏夹多个产品
- git - Git:很难让现有的 Git 存储库跟踪新的裸远程存储库
- stripe-payments - 为什么我收到 Stripe “incorrect_number” 错误?
- c# - unity AddComponent 非常低效和缓慢
- javascript - 如何安装popper v2?
- d3.js - 如何在 d3js 中将字符串转换为数字
- python - 隔离森林打印异常
- sql-server - TABLOCK 是否会提高 BULK INSERT 的性能?
- python - 如何在 discord.py 中获取调用命令的人的姓名
- python - 为什么 int2word 程序只打印前十行?