我有一個用戶,我們稱它爲「MyUser」。它有一個密碼,假設它是「密碼」。這個用戶擁有一個git的SSH密鑰。我嘗試從我的ASP.NET應用程序運行一個發出git命令的批處理文件,它位於作爲參數傳遞的位置。我的功能如下:Git從不同用戶的批文件中提取
private void ExecuteCommand(string path, int timeout)
{
Process process = new Process();
process.StartInfo = new ProcessStartInfo();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "\"" + path + "\"";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
//processInfo.WorkingDirectory = Config.GitHubRepoPath;
process.StartInfo.UserName = "MyUser";
process.StartInfo.Password = new System.Security.SecureString();
process.StartInfo.Password.AppendChar('P');
process.StartInfo.Password.AppendChar('a');
process.StartInfo.Password.AppendChar('s');
process.StartInfo.Password.AppendChar('s');
process.StartInfo.Password.AppendChar('w');
process.StartInfo.Password.AppendChar('o');
process.StartInfo.Password.AppendChar('r');
process.StartInfo.Password.AppendChar('d');
// *** Redirect the output ***
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
// *** Read the streams ***
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
if (timeout <= 0)
{
process.WaitForExit();
}
else
{
process.WaitForExit(timeout);
}
int exitCode = process.ExitCode;
process.Close();
return new ShellCommandReturn { Error = error, ExitCode = exitCode, Output = output };
}
但是當我運行這個函數時,ExitCode是-1073741502,錯誤和輸出是空的。我該如何解決這個問題?
請幫助我,我試圖解決這個字面上好幾天。
你能用這段代碼成功執行任何批處理文件嗎? –
是的,除非它們包含git pull。 –
如果是我,我會接下來驗證批處理文件運行的帳戶是否具有適當的權限。 (但那只是我。) –