This commit is contained in:
2020-05-19 22:38:10 +00:00
parent ae0c616272
commit 2906c92af9
2 changed files with 18 additions and 58 deletions

View File

@@ -10,7 +10,7 @@ namespace AyaNova.Util
{
public static string Run(string cmd, List<string> arguments, ILogger log = null)
public static string Run(string cmd, string arguments, ILogger log = null)
{
try
{
@@ -46,51 +46,26 @@ namespace AyaNova.Util
private static string RunWindows(string cmd, List<string> arguments)
private static string RunWindows(string cmd, string arguments)
{
/*
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += (sender, args) => Console.WriteLine("received output: {0}", args.Data);
process.Start();
process.BeginOutputReadLine();
//RunProgram.Run("cmd.exe",FullRunCommand, log);
// var FullRunCommand=$"/C {BackupUtilityCommand} {Arguments}";
*/
// string result = string.Empty;
// using (var process = new Process())
// {
// process.StartInfo = new ProcessStartInfo
// {
// FileName = cmd,
// Arguments = arguments,
// RedirectStandardOutput = true,
// UseShellExecute = false,
// CreateNoWindow = true,
// };
// process.OutputDataReceived += (sender, args) => result += args.Data;
// process.Start();
// // string result = process.StandardOutput.ReadToEnd();
// // process.WaitForExit();
// return result;
// }
//this executes but doesnt return error
//for Windows need to pass to cmd.exe because often have command line piping etc
var args=$"{cmd} {arguments}";
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo
{
FileName = cmd,
// Arguments = arguments,
FileName = "cmd.exe /C",
Arguments = args,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
};
foreach (string s in arguments)
process.StartInfo.ArgumentList.Add(s);
process.Start();
string result = $"{process.StandardOutput.ReadToEnd()}{process.StandardError.ReadToEnd()} ";
@@ -99,7 +74,7 @@ process.BeginOutputReadLine();
}
}
private static string RunLinuxBash(string cmd, List<string> arguments)
private static string RunLinuxBash(string cmd, string arguments)
{
var escapedArgs = $"{cmd} {arguments}".Replace("\"", "\\\"");
@@ -108,13 +83,11 @@ process.BeginOutputReadLine();
process.StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
// Arguments = $"-c \"{escapedArgs}\"",
Arguments = $"-c \"{escapedArgs}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};
foreach (string s in arguments)
process.StartInfo.ArgumentList.Add(s);
process.Start();
string result = process.StandardOutput.ReadToEnd();
@@ -124,21 +97,18 @@ process.BeginOutputReadLine();
}
private static string RunOSX(string cmd, List<string> arguments)
private static string RunOSX(string cmd, string arguments)
{
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo
{
FileName = cmd,
// Arguments = arguments,
Arguments = arguments,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};
foreach (string s in arguments)
process.StartInfo.ArgumentList.Add(s);
process.Start();
string result = process.StandardOutput.ReadToEnd();