Skip to content

Commit 4a1d3b9

Browse files
committed
fix(RunCommand): setup ExeCommandHandler
1 parent cfeba48 commit 4a1d3b9

File tree

1 file changed

+7
-38
lines changed

1 file changed

+7
-38
lines changed

src/PollinationSDK/Helper/Helper.cs

+7-38
Original file line numberDiff line numberDiff line change
@@ -895,48 +895,17 @@ public static void RunScriptFile(string scriptFile, bool silentMode)
895895
}
896896

897897

898-
public static bool RunCommand(string programPath, string argument, bool silentMode, out string results)
899-
{
900-
results = string.Empty;
901-
902-
var stdout = new List<string>();
903-
var stdErr = new List<string>();
904-
using (var p = new System.Diagnostics.Process())
905-
{
906-
p.StartInfo.FileName = programPath;
907-
p.StartInfo.Arguments = argument;
908-
p.StartInfo.UseShellExecute = false;
909-
p.StartInfo.RedirectStandardOutput = false;
910-
p.StartInfo.RedirectStandardError = true;
911-
p.StartInfo.CreateNoWindow = silentMode;
912-
p.Start();
913-
914-
p.ErrorDataReceived += (s, m) => { if (m.Data != null) stdErr.Add(m.Data); };
915-
//p.OutputDataReceived += (s, m) => { if (m.Data != null) stdout.Add(m.Data); };
916-
p.BeginErrorReadLine();
917-
//p.BeginOutputReadLine();
918-
919-
p.WaitForExit();
920-
921-
if (!p.HasExited)
922-
{
923-
p.Kill();
924-
}
898+
public delegate bool ExeCommandFunc(string program, string arg, bool silentMode, out string results);
925899

926-
}
900+
public static ExeCommandFunc ExeCommandHandler = null;
927901

928-
stdout.AddRange(stdErr);
929-
var msg = string.Join(Environment.NewLine, stdout);
930-
var cmd = $"Command:\n{programPath} {argument}";
902+
public static bool RunCommand(string programPath, string argument, bool silentMode, out string results)
903+
{
904+
if (ExeCommandHandler == null)
905+
throw new ArgumentNullException("Set Helper.ExeCommandHandler first!");
931906

932-
if (stdErr.Count > 0)
933-
{
934-
msg = $"{cmd}\n{msg}";
935-
throw new ArgumentException($"{cmd}\n{string.Join(Environment.NewLine, stdErr)}");
936-
}
907+
return ExeCommandHandler(programPath, argument, silentMode, out results);
937908

938-
results = msg;
939-
return stdErr.Count == 0;
940909
}
941910

942911

0 commit comments

Comments
 (0)