【发布时间】:2014-11-21 16:59:47
【问题描述】:
我的应用程序打开一个网站,然后运行一个 VBS 文件来进行一些数据输入。一旦完成数据输入,我想退出应用程序。
在我当前的迭代中,VBS 文件执行并且我的 C# 代码继续运行(在数据输入完成之前退出 Web 应用程序)。
Process.Start(appPath + @"external\website.url");
getAllProcesses(false);
ProcessStartInfo startInfo = new ProcessStartInfo(appPath + @"\external\UNLOCK.vbs", employeeID);
Process scriptProc = new Process();
scriptProc.StartInfo.FileName = @"cscript";
scriptProc.StartInfo.WorkingDirectory = appPath + @"external\";
scriptProc.StartInfo.Arguments = "UNLOCK.vbs " + employeeID;
scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //prevent console window from popping up
scriptProc.StartInfo.RedirectStandardError = true;
scriptProc.StartInfo.RedirectStandardInput = true;
scriptProc.StartInfo.RedirectStandardOutput = true;
scriptProc.StartInfo.ErrorDialog = false;
scriptProc.StartInfo.UseShellExecute = false;
scriptProc.Start();
scriptProc.WaitForExit(); // <-- Optional if you want program running until your script exit
Read(scriptProc.StandardOutput);
Read(scriptProc.StandardError);
while(true)
{
String completed = Console.ReadLine();
scriptProc.StandardInput.WriteLine(completed);
if(completed.CompareTo("Completed") == 0)
{
break;
}
}
if (scriptProc.HasExited)
{
getAllProcesses(true);
Application.Exit();
}
scriptProc.Close();
我只想执行
getAllProcesses(true);
Application.Exit();
仅在我从 VBS 文件中获得“已完成”的输出之后。
我的 VBS 文件有一行写着
WScript.Echo "Completed"
在最后。
【问题讨论】: