This commit is contained in:
2020-05-19 22:31:30 +00:00
parent 14f5c085f5
commit ae0c616272
3 changed files with 26 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Logging;
@@ -9,7 +10,7 @@ namespace AyaNova.Util
{
public static string Run(string cmd, string arguments, ILogger log = null)
public static string Run(string cmd, List<string> arguments, ILogger log = null)
{
try
{
@@ -45,7 +46,7 @@ namespace AyaNova.Util
private static string RunWindows(string cmd, string arguments)
private static string RunWindows(string cmd, List<string> arguments)
{
/*
process.StartInfo.UseShellExecute = false;
@@ -81,13 +82,15 @@ process.BeginOutputReadLine();
process.StartInfo = new ProcessStartInfo
{
FileName = cmd,
Arguments = arguments,
// Arguments = arguments,
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()} ";
@@ -96,7 +99,7 @@ process.BeginOutputReadLine();
}
}
private static string RunLinuxBash(string cmd, string arguments)
private static string RunLinuxBash(string cmd, List<string> arguments)
{
var escapedArgs = $"{cmd} {arguments}".Replace("\"", "\\\"");
@@ -105,11 +108,13 @@ 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();
@@ -119,18 +124,21 @@ process.BeginOutputReadLine();
}
private static string RunOSX(string cmd, string arguments)
private static string RunOSX(string cmd, List<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();