Как получить логи при установке msi?
Устанавливаю установочник setup.msi, Я увидел возможность запись логов в файл, но мне нужно выводить логи в StandardOutput? Вот такой код:
Process process = new Process();
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.Arguments = $"/l \"Setup.msi\" /q";
processInfo.FileName = "msiexec";
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
process.StartInfo = processInfo;
process.Start();
process.WaitForExit();
var exitCode = process.ExitCode;
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
Ответы (1 шт):
Думаю, примерно запуск установщика может выглядеть как то так:
public bool InstallFile(string file)
{
bool rez = true;
string fullPath = GetTempPath() + file;
Logger.WriteLog("InstallFile: path=" + fullPath);
string currentInstallLogFileName = "";
try
{
// string fullPath = GetTempPath() + p;
if (File.Exists(fullPath))
{
Logger.WriteLog("file " + fullPath + " exist");
//string sw = GetSystemDrive() + @"\WINDOWS\system32\msiexec.exe /qn /i ";
//string tCmd = sw + fullPath;
//WriteLog("Process.Start(" + tCmd + ")");
currentInstallLogFileName = GetInstallLogFileName();
Process pr = new Process();
pr.StartInfo.FileName = System.Environment.SystemDirectory + @"\msiexec.exe";
pr.StartInfo.Arguments = @"/qn /i " + fullPath + @" /l*+ """ + currentInstallLogFileName + @"""";
pr.Start();
Logger.WriteLog("InstallFile: installation process start successfully");
while(!pr.HasExited)
{
Logger.WriteLog("InstallFile: waiting");
System.Threading.Thread.Sleep(1000);
}
bool analyzeLogFileRez = AnalyzeLogFile(currentInstallLogFileName);
if (analyzeLogFileRez)
{
Logger.WriteLog("InstallFile: installation process completed successfully");
}
else
{
Logger.WriteLog("InstallFile: INSTALLATION PROCESS RETURN ERROR");
rez = false;
}
}
else
{
Logger.WriteLog("file " + fullPath + " not exist");
rez = false;
}
}
catch (Exception ex)
{
Logger.WriteLog("Error in InstallFile(): ");
Logger.WriteLog(ex.Message);
Logger.WriteLog(ex.Source);
Logger.WriteLog(ex.StackTrace);
rez = false;
}
return rez;
}
На самом деле, я просто "выдрал" эту процедуру из своего проекта, который делал примерно то же, что Вам нужно.
Здесь есть кое что лишнее, но основная иедя понятна: Вы говорите Msiexec'у, в какой файл писать лог, потом ждете завершения процесса установки, а потом анализируете этот файл.
Мне кажется, Ваш код тоже можно подправить, добавив в него еще буквально пару строк - и тогда у Вас заработает тот же самый сценарий.
В каком то смысле это костыль, и, веротяно, я не додумался, как направить вывод в standard output. Подумаю на досуге...
Успехов!