[英]How can I launch a local VBScript with arguments from a C# console application?
[英]How do I get the output from my VBScript Console using C#?
我的應用程序打開一個網站,然后運行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"
在末尾。
Process scriptProc = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.WorkingDirectory = appPath + @"external\";
info.FileName = "Cscript.exe";
info.Arguments = "UNLOCK.vbs" + employeeID;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
info.WindowStyle = ProcessWindowStyle.Hidden;
scriptProc.StartInfo = info;
scriptProc.Start();
scriptProc.WaitForExit();
bool exit = false;
while (!scriptProc.StandardOutput.EndOfStream)
{
if (scriptProc.StandardOutput.ReadLine() == "Completed")
{
exit = true;
break;
}
}
if (exit == true)
{
getAllProcesses(true);
Application.Exit();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.