testing running as user

This commit is contained in:
John Andrews
2022-03-26 16:51:37 +13:00
parent ae9d6cbb5c
commit 373d7e9ef2

View File

@@ -73,18 +73,29 @@ namespace FileFlows.VideoNodes
public async Task<ProcessResult> ExecuteShellCommand(string command, List<string> arguments, int timeout = 0)
{
var result = new ProcessResult();
string? puid = Environment.GetEnvironmentVariable("PUID2");
using (var process = new Process())
{
this.process = process;
// If you run bash-script on Linux it is possible that ExitCode can be 255.
// To fix it you can try to add '#!/bin/bash' header to the script.
process.StartInfo.FileName = command;
if (puid != null)
{
Logger?.ILog("Running command as user: " + puid);
process.StartInfo.FileName = "runuser";
process.StartInfo.ArgumentList.Add("-u");
process.StartInfo.ArgumentList.Add(puid);
process.StartInfo.ArgumentList.Add("--");
process.StartInfo.ArgumentList.Add(command);
}
else
{
process.StartInfo.FileName = command;
}
if (arguments?.Any() == true)
{
foreach (string arg in arguments)
process.StartInfo.ArgumentList.Add(arg); ;
process.StartInfo.ArgumentList.Add(arg);
}
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;