mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
* Set permissions on log file so non-elevated process can write to it. * Replace more instances of static Logger with ILogger<T>. * Add default Docker host to known proxies. * Update Immense.RemoteControl * Update Immense.RemoteControl
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using Microsoft.Extensions.Logging;
|
|
using Remotely.Shared.Utilities;
|
|
|
|
namespace Remotely.Shared.Services
|
|
{
|
|
public interface IProcessInvoker
|
|
{
|
|
string InvokeProcessOutput(string command, string arguments);
|
|
}
|
|
|
|
public class ProcessInvoker : IProcessInvoker
|
|
{
|
|
private readonly ILogger<ProcessInvoker> _logger;
|
|
|
|
public ProcessInvoker(ILogger<ProcessInvoker> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public string InvokeProcessOutput(string command, string arguments)
|
|
{
|
|
try
|
|
{
|
|
var psi = new ProcessStartInfo(command, arguments)
|
|
{
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
Verb = "RunAs",
|
|
UseShellExecute = false,
|
|
RedirectStandardOutput = true
|
|
};
|
|
|
|
var proc = Process.Start(psi);
|
|
proc.WaitForExit();
|
|
|
|
return proc.StandardOutput.ReadToEnd();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to start process.");
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|
|
} |