From 373d7e9ef27cbc64c20c0b470c03875bee515a8a Mon Sep 17 00:00:00 2001 From: John Andrews Date: Sat, 26 Mar 2022 16:51:37 +1300 Subject: [PATCH] testing running as user --- VideoNodes/FFMpegEncoder.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/VideoNodes/FFMpegEncoder.cs b/VideoNodes/FFMpegEncoder.cs index ac10361a..9badf2e9 100644 --- a/VideoNodes/FFMpegEncoder.cs +++ b/VideoNodes/FFMpegEncoder.cs @@ -73,18 +73,29 @@ namespace FileFlows.VideoNodes public async Task ExecuteShellCommand(string command, List 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;