0

C#でrunnung 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からデータを取得できますが、スクリプトにエラーがある場合、プロセスはメッセージなしで単に閉じられます...

4

1 に答える 1

1

おっと。私のせい-追加するのを忘れた

p.BeginErrorReadLine();

そしてそれが答えです

于 2013-03-25T06:01:04.253 に答える