Skip to content

Commit

Permalink
Fix exécution de commandes
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreOlivierBrillant committed Dec 5, 2024
1 parent ad31eff commit 44e9106
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions scriptsharp/ScriptSharp/Utils/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -110,22 +111,43 @@ public static void RunCommand(string command)
};

// Exécution du processus
using (Process process = new Process { StartInfo = processStartInfo })
using (Process process = new Process())
{
process.StartInfo = processStartInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.BeginOutputReadLine();
process.BeginErrorReadLine();

var output = new List<string>();
var err = new List<string>();

process.OutputDataReceived += (sender, args) =>
{
output.Add(args.Data);
};
process.ErrorDataReceived += (sender, args) =>
{
err.Add(args.Data);
};

process.WaitForExit();

if (!string.IsNullOrEmpty(output))
if (output.Count > 0)
{
LogSingleton.Get.LogAndWriteLine(" FAIT Sortie pour : " + command);
LogSingleton.Get.LogAndWriteLine(output);
foreach (string line in output)
{
LogSingleton.Get.LogAndWriteLine(line);
}

}
if (!string.IsNullOrEmpty(error))
if (err.Count > 0)
{
LogSingleton.Get.LogAndWriteLine(" ERREUR Sortie pour : " + command);
LogSingleton.Get.LogAndWriteLine(error);
foreach (string line in err)
{
LogSingleton.Get.LogAndWriteLine(line);
}
}

}
Expand Down

0 comments on commit 44e9106

Please sign in to comment.