如何从 C# 中获取运行 VB 脚本的结果? [英] How do I get back results running a VB Script from C#?

查看:42
本文介绍了如何从 C# 中获取运行 VB 脚本的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从 C# 调用 VB 脚本,即 足够简单,但有时我需要能够从这些脚本中取回结果.我应该使用引用的方法来回读,还是应该使用不同的方法?我找到了一种使用运行空间从 powershell 脚本 取回数据的方法和管道,但我对这项技术的了解不够,不知道它是否也适用于 VB 脚本.理想情况下,我想做一些类似于 powershell 方法的事情,我可以只传递脚本的内容,而无需引用外部文件并取回结果.谁能告诉我如何做到这一点?谢谢.

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

这篇关于如何从 C# 中获取运行 VB 脚本的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆