mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Fix std out/err in InvokeProcess
This commit is contained in:
@@ -8,16 +8,16 @@ public class ProcessFailedException : Exception
|
|||||||
public string Command { get; }
|
public string Command { get; }
|
||||||
public string StdOutput { get; }
|
public string StdOutput { get; }
|
||||||
|
|
||||||
public ProcessFailedException(string command, string stdOutput)
|
public ProcessFailedException(string command, string stdOutput, string stdErr)
|
||||||
: base($"Process failed: '{command}'{Environment.NewLine}Output was -{Environment.NewLine}{stdOutput}")
|
: base($"Process failed: '{command}'{Environment.NewLine}Output was -{Environment.NewLine}{stdOutput}{Environment.NewLine}StdErr was -{Environment.NewLine}{stdErr}")
|
||||||
{
|
{
|
||||||
Command = command;
|
Command = command;
|
||||||
StdOutput = stdOutput;
|
StdOutput = stdOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ThrowIfNonZero((int ExitCode, string StdOutput, string Command) result)
|
public static void ThrowIfNonZero((int ExitCode, string StdOutput, string StdErr, string Command) result)
|
||||||
{
|
{
|
||||||
if (result.ExitCode != 0)
|
if (result.ExitCode != 0)
|
||||||
throw new ProcessFailedException(result.Command, result.StdOutput);
|
throw new ProcessFailedException(result.Command, result.StdOutput, result.StdErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public static class Exe
|
|||||||
if (VelopackRuntimeInfo.IsWindows) {
|
if (VelopackRuntimeInfo.IsWindows) {
|
||||||
var output = InvokeAndThrowIfNonZero("where", new[] { binaryName }, null);
|
var output = InvokeAndThrowIfNonZero("where", new[] { binaryName }, null);
|
||||||
if (String.IsNullOrWhiteSpace(output) || !File.Exists(output))
|
if (String.IsNullOrWhiteSpace(output) || !File.Exists(output))
|
||||||
throw new ProcessFailedException("", "");
|
throw new ProcessFailedException("", "", "");
|
||||||
} else if (VelopackRuntimeInfo.IsOSX) {
|
} else if (VelopackRuntimeInfo.IsOSX) {
|
||||||
InvokeAndThrowIfNonZero("command", new[] { "-v", binaryName }, null);
|
InvokeAndThrowIfNonZero("command", new[] { "-v", binaryName }, null);
|
||||||
} else if (VelopackRuntimeInfo.IsLinux) {
|
} else if (VelopackRuntimeInfo.IsLinux) {
|
||||||
@@ -65,7 +65,7 @@ public static class Exe
|
|||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
|
|
||||||
var stdout = Utility.Retry(() => File.ReadAllText(outputFile).Trim(), 10, 1000);
|
var stdout = Utility.Retry(() => File.ReadAllText(outputFile).Trim(), 10, 1000);
|
||||||
var result = (process.ExitCode, stdout, command);
|
var result = (process.ExitCode, stdout, "", command);
|
||||||
ProcessFailedException.ThrowIfNonZero(result);
|
ProcessFailedException.ThrowIfNonZero(result);
|
||||||
return result.Item2;
|
return result.Item2;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ public static class Exe
|
|||||||
return result.StdOutput;
|
return result.StdOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (int ExitCode, string StdOutput) InvokeProcess(ProcessStartInfo psi, CancellationToken ct)
|
public static (int ExitCode, string StdOutput, string StdErr) InvokeProcess(ProcessStartInfo psi, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var process = new Process();
|
var process = new Process();
|
||||||
process.StartInfo = psi;
|
process.StartInfo = psi;
|
||||||
@@ -134,11 +134,10 @@ public static class Exe
|
|||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
var all = (sOut.ToString().Trim()) + Environment.NewLine + (sOut.ToString().Trim());
|
return (process.ExitCode, sOut.ToString().Trim(), sErr.ToString().Trim());
|
||||||
return (process.ExitCode, all.Trim());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (int ExitCode, string StdOutput, string Command) InvokeProcess(string fileName, IEnumerable<string> args, string workingDirectory, CancellationToken ct = default,
|
public static (int ExitCode, string StdOutput, string StdErr, string Command) InvokeProcess(string fileName, IEnumerable<string> args, string workingDirectory, CancellationToken ct = default,
|
||||||
IDictionary<string, string> envVar = null)
|
IDictionary<string, string> envVar = null)
|
||||||
{
|
{
|
||||||
var psi = CreateProcessStartInfo(fileName, workingDirectory);
|
var psi = CreateProcessStartInfo(fileName, workingDirectory);
|
||||||
@@ -150,7 +149,7 @@ public static class Exe
|
|||||||
|
|
||||||
psi.AppendArgumentListSafe(args, out var argString);
|
psi.AppendArgumentListSafe(args, out var argString);
|
||||||
var p = InvokeProcess(psi, ct);
|
var p = InvokeProcess(psi, ct);
|
||||||
return (p.ExitCode, p.StdOutput, $"{fileName} {argString}");
|
return (p.ExitCode, p.StdOutput, p.StdErr, $"{fileName} {argString}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProcessStartInfo CreateProcessStartInfo(string fileName, string workingDirectory)
|
public static ProcessStartInfo CreateProcessStartInfo(string fileName, string workingDirectory)
|
||||||
|
|||||||
Reference in New Issue
Block a user