From ebb26ae709570a84004c27f34e9307c33ac6b000 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Fri, 19 Apr 2024 00:55:07 +0200 Subject: Add Solution --- solve/PhotoEditor/Controllers/BaseAPIController.cs | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 solve/PhotoEditor/Controllers/BaseAPIController.cs (limited to 'solve/PhotoEditor/Controllers/BaseAPIController.cs') diff --git a/solve/PhotoEditor/Controllers/BaseAPIController.cs b/solve/PhotoEditor/Controllers/BaseAPIController.cs new file mode 100644 index 0000000..0c2acf3 --- /dev/null +++ b/solve/PhotoEditor/Controllers/BaseAPIController.cs @@ -0,0 +1,32 @@ +using System.Diagnostics; +using Microsoft.AspNetCore.Mvc; +using PhotoEditor.Models; + +namespace PhotoEditor.Controllers; + +public class BaseAPIController : ControllerBase +{ + public String GetUsername(Dictionary env) { + Process process = new Process(); + process.StartInfo.FileName = "bash"; + process.StartInfo.Arguments = "-c 'whoami'"; + + foreach (var kv in env) + { + Console.WriteLine(kv.Key + ":" + kv.Value); + process.StartInfo.EnvironmentVariables[kv.Key] = kv.Value; + } + + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.Start(); + string output = process.StandardOutput.ReadToEnd(); + Console.WriteLine(output); + string err = process.StandardError.ReadToEnd(); + Console.WriteLine(err); + process.WaitForExit(); + + return output + err; + } +} \ No newline at end of file -- cgit v1.2.3-71-gd317