Starting from Excel (VBA): Launch an external interactive program, and in there launch commands and read their output : is this possible?

坚强是说给别人听的谎言 提交于 2019-12-20 04:07:26

问题


Currently I'm doing the following for analysing a memory leak:

  1. I open both dumps, using Windbg.
  2. I launch heap_stat script, a Python-based script for making a summary of the objects, used in the heap.
  3. I copy the results of both heap_stat scripts, and paste them in an Excel sheet, where the results are analysed.

I'd like to automate this, starting from the final Excel sheet, using VBA, as follows:

  1. Start two instances of an external program (Windbg.exe) and open both dumps with them.
  2. In those Windbg instances, launch the necessary commands (.load pykd.pykd, followed by .py heap_stat.py -stat).
  3. Wait for the heap_stat.py script to finish, and copy the result to the Excel sheet.
  4. Add some necessary Match() worksheet functions and Excel formulas for completing the analysis.

In order to do this, I need to be able to:

  1. Launch an external program from VBA. This can be done, using the Shell command.
  2. 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.
  3. Wait for everything to be finished. This can be done using this link.
  4. 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?


回答1:


If you want to use pykd for fully automatic tasks, why you need to run it inside windbg? You can make a standalone python script.




回答2:


I've found following solution to my problem:

  • 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
    
    • 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
      
  • I'll write a while-loop, verifying for the presence of the flag file.
  • The output file's content will be copied to the Excel file, which will do the analysis.


来源:https://stackoverflow.com/questions/54292846/starting-from-excel-vba-launch-an-external-interactive-program-and-in-there

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!