我無法調用與模擬(.NET 4.0)的批處理文件起動過程中不與模擬
我有一個調用駐留在服務器的本地文件系統上的測試批處理文件的Web應用程序的工作。當我沒有模仿地運行它時,它運行良好。但是通過模擬,批處理文件不會產生任何輸出,也不會返回任何錯誤。
下面是執行,我使用批處理文件中的代碼 -
public static bool ExecuteBatchFile(string fileLocationPath, string filePath, string arguments, TextBox textBox)
{
try
{
ProcessStartInfo procStartInfo = new ProcessStartInfo(filePath);
procStartInfo.UseShellExecute = false;
procStartInfo.Arguments = arguments;
procStartInfo.WorkingDirectory = fileLocationPath;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.RedirectStandardInput = true;
procStartInfo.UserName = "XYZ";
procStartInfo.Domain = "ABC";
System.Security.SecureString pwd = new System.Security.SecureString();
foreach (char c in "PWD")
pwd.AppendChar(c);
procStartInfo.Password = pwd;
procStartInfo.LoadUserProfile = true;
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
textBox.Text += "output rcvd\r\n";
textBox.Text += e.Data;
};
proc.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
textBox.Text += "error rcvd\r\n";
textBox.Text += e.Data;
};
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();
proc.Close();
return true;
}
catch (Exception e)
{
textBox.Text += e.Message;
return false;
}
}
沒有冒充我可以看到該批處理文件的輸出。我得到的輸出與批處理文件的輸出接收,然後是一個空的OutputReceived,然後是一個空的ErrorReceived。
但隨着模仿,我什麼都看不到!只有一個OutputReceived沒有數據的事件,一個沒有數據的ErrorReceived事件。
我已經在Web配置文件中設置模擬如下:
<identity impersonate="true" userName="ABC\XYZ" password="PWD"/>