2013-03-25 53 views
0

我怎样才能正确地从runnung vbscript在C#中获取错误输出?从vbscript获取错误输出

这里是我的代码:

System.Diagnostics.Process p = new System.Diagnostics.Process(); 
p.StartInfo = new System.Diagnostics.ProcessStartInfo("cscript"); 
p.StartInfo.CreateNoWindow = true; 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.RedirectStandardOutput = true; 

p.OutputDataReceived += (proc, outLine) => MessageBox.Show(outLine.Data, 
                  "Data:", 
                  MessageBoxButtons.OK, 
                  MessageBoxIcon.Information); 
p.ErrorDataReceived += (proc, outLine) => MessageBox.Show(outLine.Data, 
                  "error!", 
                  MessageBoxButtons.OK, 
                  MessageBoxIcon.Error); 

p.StartInfo.Arguments = "C:\\test.vbs"; 

p.Start(); 

p.BeginOutputReadLine(); 

这样,我能够从CSCRIPT获得的数据,但如果有脚本错误 - 过程干脆关门,没有消息......

+0

为downvote有何评论? – JleruOHeP 2013-03-25 05:56:13

回答

1

OOps。我的错 - 我忘了补充

p.BeginErrorReadLine(); 

这就是答案