使用ProcessStartInfo C#执行脚本 [英] Execute script with ProcessStartInfo C#

查看:55
本文介绍了使用ProcessStartInfo C#执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从C#应用程序执行的vbscript;它工作正常,但是如何监视该过程以确保它没有挂起?我怎么知道vbscript已经完成,如果挂了,我该如何杀死它?
感谢您的帮助.
斯科特

I have a vbscript I execute from my C# application; it works fine, but how can I monitor the process to make sure it didn''t hang? How do I know the vbscript finished and if it hangs, how can I kill it?
Thanks for any help.
Scott

ProcessStartInfo si = new ProcessStartInfo();

si.FileName = "cscript.exe";
si.RedirectStandardOutput = true;                
si.Arguments = "Script.vbs";
si.UseShellExecute = false;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.CreateNoWindow = true;
Process p = Process.Start(si);

string searchResult = p.StandardOutput.ReadToEnd();
p.WaitForExit();

推荐答案

您可以使用计时器检查p是否在一定时间后退出,而不用调用WaitForExit.实际上,我认为WaitForExit可以采用超时值.
You can use a timer to check if p has exited after a certain period of time, instead of calling WaitForExit. Actually, I think WaitForExit can take a timeout value.


能否给我一个使用Win32 API而不使用CSCript.exe的示例吗?

谢谢

Scott
Can you give me an example of using the Win32 API instead of using CSCript.exe?

thanks

Scott


不建议使用"cscript.exe",它将启动新进程,您无法再监视其他进程中的其他进程信息,这需要调用WIN32 API来完成,无法在.net框架中完成
no recommend use "cscript.exe",it will start new proccess, you can''t monitor other process informations more in different process, this need to call the WIN32 API to do, can''t go do in .net framework


这篇关于使用ProcessStartInfo C#执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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