我希望从我的c#代码中调用外部程序.
我调用的程序,假设foo.exe返回大约12行文本.
我想调用程序并通过输出解析.
这样做的最佳方式是什么?
代码片段也赞赏:)
非常感谢你.
可能重复:
加载EXE文件并使用C#从内存运行它
我正在使用WebClient类从Web服务器下载.exe.有没有办法可以运行.exe而不先将其保存到磁盘?
为了完整起见,让我告诉你到目前为止我所拥有的.
这是我用来开始下载的代码:
WebClient webClient = new WebClient();
webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(webClient_DownloadDataCompleted);
webClient.DownloadDataAsync(new Uri("http://www.somewebsite.com/calc.exe"));
Run Code Online (Sandbox Code Playgroud)
在(webClient_DownloadDataCompleted)方法中,我只需从参数e中获取字节:
private void webClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
Byte[] downloadedData = e.Result;
// how to run this like a .exe?
}
Run Code Online (Sandbox Code Playgroud)
谢谢.