1

我想在我的控制台应用程序上使用一个名为 jlink.exe 的可执行文件。因为 jlink.exe 不是 .net 应用程序,所以我无法引用它并调用它的方法。结果,我想用它来读取它的输出

当我从 Windows 资源管理器启动该 exe 时,它​​的外观如下: 在此处输入图像描述

然后它等待一个命令。如果我输入mem 88 2然后我回来:

在此处输入图像描述

现在我想用我的 .net 控制台应用程序做同样的事情来读取它的标准输出,但由于某种原因我无法读取输出。这就是我所拥有的:

    // change working directory
    Directory.SetCurrentDirectory(@"C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.4 Evaluation\arm\bin");

    Process p = new Process( )
    {
        StartInfo = new ProcessStartInfo( @"jlink.exe" )
        {
            UseShellExecute = false ,
            RedirectStandardOutput = true ,
            RedirectStandardInput = true
        }
    };

    p.Start( );                       

    StreamWriter standardInput = p.StandardInput;
    StreamReader standardOutput = p.StandardOutput;

    var line = string.Empty;

    while ( ( line = standardOutput.ReadLine( ) ) != null )
    {                
        Console.WriteLine( line );                
    }

为什么当我运行该代码时,我只是得到一个黑色窗口......我没有得到与运行该可执行文件时相同的输出。当我针对其他可执行文件运行该代码时,它工作得很好。

如果我然后键入mem 88 2并按 ENTER,则没有任何反应。如果我再按一次回车,那么我最终会得到我想要的额外内容。为什么我会在该可执行文件中出现这种行为?

编辑

我看过类似的问题,例如这个:

process.standardoutput.ReadToEnd() 总是空的?

我不认为我做错了什么。我想那个可执行文件有些奇怪。要使用该可执行文件,您可以从以下网址下载它: http ://supp.iar.com/Download/SW/?item=EWARM-EVAL或http://www.iar.com/en/Products/IAR-Embedded-工作台/ARM/ . 然后去C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.4 Evaluation\arm\bin执行jlink.exe(如果你没有通过usb连接板你会得到一个错误但没关系。错误信息也不会出现)。

4

0 回答 0