在C中调用Python作为进程#

2024-09-30 16:25:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在Windows中安装了olevba,因此,我可以在命令提示符下运行它,从vbaProject.bin检索VBA宏:

enter image description here

现在,我想在Visual Studio中启动它,因此添加了以下代码:

public static void printMacros()
{
    Process p = new Process();
    p.StartInfo.FileName = "python.exe";
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.Arguments = "../../oletools-0.46/oletools/olevba.py ../../oletools-0.46/oletools/vbaProject.bin";
    p.Start();
    StreamReader s = p.StandardOutput;
    String output = s.ReadToEnd();
    string[] r = output.Split(new char[] { ' ' });
    Console.WriteLine(r[0]);
    p.WaitForExit();
}

但是,汇编并没有很好地显示结果:

enter image description here

请注意,p.StartInfo.Arguments中的路径../../oletools-0.46/oletools/olevba.py是正确的,否则将引发No such file or directory错误;而将第二个参数../../oletools-0.46/oletools/vbaProject.bin更改为不相关的文件总是返回相同的结果。在

有人知道这里怎么了吗?在


Tags: pynewoutputbinwindowsvbaprocessarguments