How do I get back results running a VB Script from C#?
I want to be able to call VB scripts from C#, which is easy enough, but I need to be able to get back the results from these scripts at tim开发者_如何学Goes. Should I use the method referenced with something to read back, or should I use a different method? I've found a method to getting data back from powershell scripts using Runspaces and Pipelines, but I don't know enough about this technology to know if it will work with VB scripts as well. Ideally, I'd like to do something similar to the powershell method where I can just pass in the contents of the script without needing to reference an external file and get back the results. Can anyone tell me how to do this? Thanks.
Here's a pretty simple way to do it by listening to an event:
Process vbsProcess = new Process();
vbsProcess.StartInfo.FileName = "yourscript.vbs";
vbsProcess.StartInfo.UseShellExecute = false;
vbsProcess.StartInfo.RedirectStandardOutput = true;
vbsProcess.OutputDataReceived += new DataReceivedEventHandler(YourOutputHandler);
vbsProcess.Start();
vbsProcess.WaitForExit();
精彩评论