case 4706 - remove the unused RunProgram.Run and its shell helpers
Run, RunWindows (cmd.exe /C), RunLinuxShell (/bin/sh -c) and RunOSX have had no callers since the backup moved to RunNoShell. Backup through the API and the integration suite unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AyaNova.Util
|
||||
@@ -11,42 +10,6 @@ namespace AyaNova.Util
|
||||
{
|
||||
|
||||
|
||||
public static string Run(string cmd, string arguments, ILogger log = null, int waitForExitTimeOut = int.MaxValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return RunWindows(cmd, arguments, waitForExitTimeOut);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
return RunOSX(cmd, arguments, waitForExitTimeOut);
|
||||
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
return RunLinuxShell(cmd, arguments, waitForExitTimeOut);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (log != null)
|
||||
{
|
||||
log.LogError(ex, $"RunProgram error running command:{cmd} {arguments}");
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
throw new PlatformNotSupportedException();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Run a program directly, no shell: each argument is passed as-is (no quoting or escaping needed, nothing is interpreted by a shell)
|
||||
/// and extra environment variables are set for this process only (e.g. PGPASSWORD so a password never appears on a command line)
|
||||
@@ -98,87 +61,5 @@ namespace AyaNova.Util
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static string RunWindows(string cmd, string arguments, int waitForExitTimeOut = int.MaxValue)
|
||||
{
|
||||
//RunProgram.Run("cmd.exe",FullRunCommand, log);
|
||||
// var FullRunCommand=$"/C {BackupUtilityCommand} {Arguments}";
|
||||
|
||||
//for Windows need to pass to cmd.exe because often have command line piping etc
|
||||
var args = $"/C {cmd} {arguments}";
|
||||
using (var process = new Process())
|
||||
{
|
||||
process.StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "cmd.exe",
|
||||
Arguments = args,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
|
||||
|
||||
process.Start();
|
||||
|
||||
string result = $"{process.StandardOutput.ReadToEnd()}{process.StandardError.ReadToEnd()} ";
|
||||
if (!process.WaitForExit(waitForExitTimeOut))
|
||||
{
|
||||
result += $"\nERROR: TIMED OUT {waitForExitTimeOut}ms BEFORE COMPLETION";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static string RunLinuxShell(string cmd, string arguments, int waitForExitTimeOut = int.MaxValue)
|
||||
{
|
||||
var escapedArgs = $"{cmd} {arguments}".Replace("\"", "\\\"");
|
||||
|
||||
using (var process = new Process())
|
||||
{
|
||||
process.StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "/bin/sh",
|
||||
Arguments = $"-c \"{escapedArgs}\"",
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
|
||||
process.Start();
|
||||
string result = process.StandardOutput.ReadToEnd();
|
||||
if (!process.WaitForExit(waitForExitTimeOut))
|
||||
{
|
||||
result += $"\nERROR: TIMED OUT {waitForExitTimeOut}ms BEFORE COMPLETION";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static string RunOSX(string cmd, string arguments, int waitForExitTimeOut = int.MaxValue)
|
||||
{
|
||||
using (var process = new Process())
|
||||
{
|
||||
process.StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = cmd,
|
||||
Arguments = arguments,
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
|
||||
process.Start();
|
||||
string result = process.StandardOutput.ReadToEnd();
|
||||
if (!process.WaitForExit(waitForExitTimeOut))
|
||||
{
|
||||
result += $"\nERROR: TIMED OUT {waitForExitTimeOut}ms BEFORE COMPLETION";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user