0

How can I correctly get error output from runnung vbscript in C#?

Here is my code:

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();  

This way I am able to get data from cscript, but if there is an error in the script - process is simply closed, without a message...

0

1 Answer 1

1

OOps. My fault - I forgot to add

p.BeginErrorReadLine();

And that is the answer

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.