从Excel(VBA)开始:启动一个外部交互式程序,然后在其中启动命令并读取其输出:这可能吗? [英] Starting from Excel (VBA): Launch an external interactive program, and in there launch commands and read their output : is this possible?
问题描述
目前,我正在执行以下操作来分析内存泄漏:
Currently I'm doing the following for analysing a memory leak:
- 我使用Windbg打开两个转储.
- 我启动heap_stat脚本,这是一个基于Python的脚本,用于汇总堆中使用的对象.
- 我复制两个heap_stat脚本的结果,然后将它们粘贴到用于分析结果的Excel工作表中.
我想使用VBA从最终的Excel工作表开始自动执行此操作,如下所示:
I'd like to automate this, starting from the final Excel sheet, using VBA, as follows:
- 启动一个外部程序(
Windbg.exe
)的两个实例,并使用它们打开两个转储. - 在那些
Windbg
实例中,启动必要的命令(.load pykd.pykd
,然后是.py heap_stat.py -stat
). - 等待
heap_stat.py
脚本完成,然后将结果复制到Excel工作表中. - 添加一些必要的
Match()
工作表功能和Excel公式以完成分析.
- Start two instances of an external program (
Windbg.exe
) and open both dumps with them. - In those
Windbg
instances, launch the necessary commands (.load pykd.pykd
, followed by.py heap_stat.py -stat
). - Wait for the
heap_stat.py
script to finish, and copy the result to the Excel sheet. - Add some necessary
Match()
worksheet functions and Excel formulas for completing the analysis.
为此,我需要能够:
- 从VBA启动一个外部程序.可以使用
Shell
命令来完成. - 在该外部程序中,启动另外两个命令. (启动一个命令很容易,如此处所述,但是两个呢?)在无法执行此操作的情况下:
Windbg
允许使用分号连接命令,因此可以跳过.为了执行此操作,我正在考虑上述URL中解释的技巧. - 等待一切完成.可以使用此链接来完成.
- 读取输出.
- Launch an external program from VBA. This can be done, using the
Shell
command. - Within that external program, launch two other commands. (Launching one command is easy, as explained here, but what about two?) In case this is not possible:
Windbg
allows concatenating commands, using a semi-colon, so that can be skipped. In order to perform this, I'm thinking about the trick, explained in mentioned URL. - Wait for everything to be finished. This can be done using this link.
- Read the output.
我的问题是:是否可以读取输出?我知道可以等待命令完成,以验证结果是否正确或是否有错误,但是我找不到找到读取命令所抛出的实际输出的方法.
My issue is : is it possible to read the output? I know it is possible to wait for a command to finish, to verify if the result is ok or if there is an error, but I don't find a way to read the actual output, thrown by the command.
有人知道这是否(轻松)可行吗?
Does anybody know if this is (easily) feasible?
推荐答案
我发现了以下解决问题的方法:
I've found following solution to my problem:
- 我将修改我的heap_stat脚本,最后将创建一个空的(标志)文件.
-
我将通过Excel VBA进行如下操作:
- I'll adapt my heap_stat script, at the end it'll create an empty (flag) file.
I'll windbg from Excel VBA as follows:
Shell "windbg -z ""C:\Directory\Dumpfile.dmp"" -c "".load pykd.pyd;.logopen C:\Directory\output.txt;!py heap_stat.py -stat""", vbMaximizedFocus
-
Windbg命令的含义如下:
The meaning of the Windbg commands is the following:
.load pykd.pyd // load PYKD library .logopen ... // open a logfile, for all Windbg output (thanks, Zac and Tate, for the idea) !py heap_stat.py -stat // launch the heap_stat script
这篇关于从Excel(VBA)开始:启动一个外部交互式程序,然后在其中启动命令并读取其输出:这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!