Files
.vscode
ADO2024
ADO2025
Day
Helpers
Exif
HelperCreateNoteFiles.cs
HelperDeleteEmptyDirectories.cs
HelperDirectory.cs
HelperFindReplace.cs
HelperGenealogicalDataCommunication.cs
HelperGit.cs
HelperILMerge.cs
HelperKanbanMetadata.cs
HelperLogMerge.cs
HelperMarkdown.cs
HelperNPM.cs
HelperPackageFilesByDate.cs
HelperPdfStripperWrapper.cs
HelperRenameToOldMoveDeleteOld.cs
HelperSaveOrCopyContents.cs
HelperStart.cs
HelperTooLong.cs
HelperZipFilesBy.cs
RijndaelEncryption.cs
Models
Scripts
Server-Management
.editorconfig
.gitignore
.prettierignore
Dockerfile
File-Folder-Helper.csproj
Program.cs
README.md
Worker.cs
docker-compose.yaml
global.json
package-lock.json
package.json
file-folder-helper/Helpers/HelperStart.cs
Mike Phares 5fe51ef645 nuget bump
2023-11-02
2023-11-08
net8.0
editorconfig
NuGet NuSpec
Kanban
2023-11-14 07:54:34 -07:00

55 lines
2.2 KiB
C#

using System.Diagnostics;
using System.Text;
namespace File_Folder_Helper.Helpers;
internal static class HelperStart
{
internal static bool Start(string[] errorChecks, string[] successChecks, ProcessStartInfo processStartInfo, string errorFile)
{
bool result = false;
string standardError = string.Empty;
string standardOutput = string.Empty;
StringBuilder stringBuilder = new();
Process? process = Process.Start(processStartInfo);
long breakAfter = DateTime.Now.AddSeconds(20).Ticks;
for (short j = 0; j < short.MaxValue; j++)
{
if (process is null || process.HasExited || process.WaitForExit(500) || DateTime.Now.Ticks > breakAfter)
break;
}
if (process is not null && processStartInfo.RedirectStandardOutput)
{
_ = stringBuilder.Append(process.StandardOutput.ReadToEnd());
standardOutput = stringBuilder.ToString();
if (string.IsNullOrEmpty(standardOutput))
standardOutput = string.Concat(standardOutput);
if (!string.IsNullOrEmpty(standardOutput))
{
result = (from l in successChecks where standardOutput.Contains(l) select 1).Any();
if (result)
result = !(from l in errorChecks where standardOutput.Contains(l) select 1).Any();
}
}
if (process is not null && processStartInfo.RedirectStandardError)
{
standardError = process.StandardError.ReadToEnd();
if (!string.IsNullOrEmpty(standardError))
{
if (result)
{
result = (from l in successChecks where standardError.Contains(l) select 1).Any();
if (result)
result = !(from l in errorChecks where standardError.Contains(l) select 1).Any();
}
}
}
if (!result)
result = standardOutput == string.Empty && standardError == string.Empty;
if (!result)
File.WriteAllLines(errorFile, [standardOutput, Environment.NewLine, Environment.NewLine, standardError]);
return result;
}
}