Код: Выделить всё
var ffmpeg = $"/home/site/wwwroot/ffmpeg";
var videoPath = Path.GetFullPath($"SampleVideo1.mp4");
var ffmpegCommand = $"{ffmpeg} -i \"{videoPath}\"";
using Process process = new();
process.StartInfo.FileName = "bash";
process.StartInfo.Arguments = $"-c \"{ffmpegCommand}\"";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
var output = await process.StandardOutput.ReadToEndAsync();
var error = await process.StandardError.ReadToEndAsync();
await process.WaitForExitAsync();
Проблемы, с которыми я столкнулся:
- Использование сценария/исполняемого файла напрямую (без bash) с UseShellExecute = false приводит к ошибке отказа в разрешении (при использовании Process.Start() сообщается, что разрешение отклонено)
- Использование сценария/исполняемого файла напрямую с UseShellExecute = true приводит к невозможности получения выходных данных/данных об ошибках из процесса.
В качестве дополнительного решения я пытаюсь запустить bash с UseShellExecute = true и сохранить вывод в файл с помощью -c "commandhere > somefile.txt.
В обоих случаях я получаю сообщение об ошибке:
Код: Выделить всё
bash: line 1: /home/site/wwwroot/ffmpeg: Permission denied\n
Код: Выделить всё
var chmodStartInfo = new ProcessStartInfo
{
FileName = "chmod",
Arguments = $"+x {ffmpegPath}",
RedirectStandardOutput = false,
RedirectStandardError = false,
UseShellExecute = true,
CreateNoWindow = true
};
using (var chmodProcess = new Process { StartInfo = chmodStartInfo })
{
chmodProcess.Start();
await chmodProcess.WaitForExitAsync();
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ns-c-linux
Мобильная версия