This commit is contained in:
2020-05-19 21:16:47 +00:00
parent 7b963c60c3
commit 2b61791f2a
2 changed files with 33 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Logging;
namespace AyaNova.Util
{
@@ -8,25 +9,38 @@ namespace AyaNova.Util
{
public static string Run(string cmd, string arguments)
public static string Run(string cmd, string arguments, ILogger log = null)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
try
{
return RunWindows(cmd, arguments);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return RunOSX(cmd, arguments);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return RunWindows(cmd, arguments);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return RunOSX(cmd, arguments);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return RunLinuxBash(cmd, arguments);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
catch (Exception ex)
{
return RunLinuxBash(cmd, arguments);
}
else
{
throw new PlatformNotSupportedException();
if (log != null)
{
log.LogError(ex, $"RunProgram error running command:{cmd} {arguments}");
}
throw ex;
}
throw new PlatformNotSupportedException();
}