-1

在数据流任务中,我需要将每一行重定向到 exe 并获取每一行的输出,类似于脚本组件。

我尝试在脚本组件中使用 Process,但它抛出异常“StandardOut 尚未重定向或进程尚未启动。”。脚本组件中使用的代码是:

 Process myApp = new Process();
 myApp.StartInfo.FileName = @"Someexe.exe";
 myApp.StartInfo.Arguments = "param1";
 myApp.StartInfo.UseShellExecute = false;
 myApp.StartInfo.RedirectStandardOutput = false;

 myApp.Start();
 while (!myApp.HasExited)
 {
  string result= myApp.StandardOutput.ReadToEnd();
  }

有什么建议么?我想知道是否有更好的方法来做到这一点?

4

1 回答 1

0

您的错误消息很有帮助:“StandardOut has not been redirected...”由于您想捕获输出,将其重定向到目标组件,您不想更改行:

myApp.StartInfo.RedirectStandardOutput = false;

成为:

myApp.StartInfo.RedirectStandardOutput = true;


考虑此链接上的示例,在 BOL 上:
ProcessStartInfo.RedirectStandardOutput 属性

于 2014-03-13T06:48:11.697 回答