blob: 0c2acf30073f60bc87fdd07ee17b6cbd73656a33 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using PhotoEditor.Models;
namespace PhotoEditor.Controllers;
public class BaseAPIController : ControllerBase
{
public String GetUsername(Dictionary<String,String> 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;
}
}
|