/// <summary> /// Reboot implementation on UNIX Operating System /// </summary> public void Reboot() { var pathToShutdown = Path.Combine(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), "sbin", "shutdown"); var shutdownArgs = string.Format(CultureInfo.InvariantCulture, "{0} -r now", pathToShutdown); var cfg = new ShellCommandOptions("sudo", shutdownArgs); using var process = new AbbotwareShellCommand(cfg, NullLogger.Instance); var result = process.Execute(); // If there is data from standard error then the command // didn't work because we are not executing as root if (!result.StartInfo.Started) { throw AbbotwareException.Create("Error during shell command {0}", result.ErrorOutput.FirstOrDefault().Message); } if (!result.Exited) { throw AbbotwareException.Create("Error during shell command {0}", result.ErrorOutput.FirstOrDefault().Message); } if (result.ExitCode != 0) { throw AbbotwareException.Create("Error during shell command {0}", result.ErrorOutput.FirstOrDefault().Message); } }
/// <summary> /// Creates an X509 certificate /// </summary> /// <param name="hostName">hostname used to create certificate</param> /// <param name="output">output location</param> public static void Create(string hostName, Uri output) { Arguments.NotNullOrWhitespace(hostName, nameof(hostName)); output = Arguments.EnsureNotNull(output, nameof(output)); var arguments = string.Format(CultureInfo.InvariantCulture, X509.ArgumentsTemplate, hostName, output.LocalPath); var cfg = new ShellCommandOptions(X509.Command, arguments) { CommandTimeout = CommandTimeout, }; using var cp = new AbbotwareShellCommand(cfg, NullLogger.Instance); var result = cp.Execute(); if (!result.StartInfo.Started) { var message = FormattableString.Invariant($"Failed to Start:{X509.Command} {arguments}"); throw new AbbotwareException(message); } if (!result.Exited) { var message = FormattableString.Invariant($"Wait For Exit failed::{X509.Command} {arguments}"); throw new AbbotwareException(message); } }
public async Task ShellCommand_FileNotFound() { var cfg = new ShellCommandOptions("notfound.exe") { WorkingDirectory = Environment.CurrentDirectory, }; using var child = new AbbotwareShellCommand(cfg, this.Logger); var r = await child.ExecuteAsync(default);