C# asp.net 웹 페이지를 사용하여 내 서버에서 .ps1 PowerShell 파일을 실행하려고합니다. 스크립트는 매개 변수 하나를 사용하며 서버에서 명령 프롬프트를 사용하여 작동하는지 확인했습니다. 실행 후 결과를 웹 페이지에 표시해야합니다.서버에서 powershell .ps1 파일 실행 및 결과보기 C# asp.net
현재 내가 사용하고 있습니다 :
protected void btnClickCmdLine(object sender, EventArgs e)
{
lblResults.Text = "Please wait...";
try
{
string tempGETCMD = null;
Process CMDprocess = new Process();
System.Diagnostics.ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo();
StartInfo.FileName = "cmd"; //starts cmd window
StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
StartInfo.CreateNoWindow = true;
StartInfo.RedirectStandardInput = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.UseShellExecute = false; //required to redirect
CMDprocess.StartInfo = StartInfo;
CMDprocess.Start();
lblResults.Text = "Starting....";
System.IO.StreamReader SR = CMDprocess.StandardOutput;
System.IO.StreamWriter SW = CMDprocess.StandardInput;
SW.WriteLine("@echo on");
SW.WriteLine("cd C:\\Tools\\PowerShell\\");
SW.WriteLine("powershell .\\poweron.ps1 **parameter**");
SW.WriteLine("exit"); //exits command prompt window
tempGETCMD = SR.ReadToEnd(); //returns results of the command window
lblResults.Text = tempGETCMD;
SW.Close();
SR.Close();
}
catch (Exception ex)
{
lblErrorMEssage.Text = ex.ToString();
showError();
}
}
그러나, 심지어는 초기 표시되지 않습니다 "기다려주십시오 ..."나는 PowerShell을 호출하는 줄을 포함합니다. ScriptManager에서 AsyncPostBackTimeout을 늘려도 결국 결국 시간 초과됩니다. 누구나 내가 뭘 잘못하고 있다고 말할 수 있습니까? 감사합니다
poweron.ps1이란 무엇입니까? 어떤 소스 코드? . http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts – Kiquenet