Skip to content
Snippets Groups Projects
Commit 91bc1e15 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Fix exec pouze z $PATH a ne .

parent 89948bd8
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ using System.Runtime.InteropServices;
using Color = System.Drawing.Color;
using Process = System.Diagnostics.Process;
using ProcessStartInfo = System.Diagnostics.ProcessStartInfo;
using System.Net.Http;
using Config;
......@@ -322,11 +323,60 @@ class ModuleExec: ModuleAbstractPipe
}
protected override StreamReader getPipe()
{
process = new();
process.StartInfo.FileName = programName;
process.StartInfo.Arguments = arguments;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
static string FindExecutableInPath(string command)
{
// Získání proměnné PATH z prostředí
string pathEnv = Environment.GetEnvironmentVariable("PATH");
if (string.IsNullOrEmpty(pathEnv))
return string.Empty;
string[] paths = pathEnv.Split(':');
// Prohledání všech cest v PATH
foreach (string path in paths)
{
// Vytvoření úplné cesty k binárce
string fullPath = Path.Combine(path, command);
// Na Unixu je důležité hledat spustitelný soubor (pomocí File.Exists a kontrolou práv)
if (File.Exists(fullPath))
{
return fullPath;
}
}
return string.Empty;
}
static bool IsExecutable(string path)
{
// Na Windows stačí File.Exists
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
return true;
// Na Unixu kontrolujeme, zda má soubor nastavené spustitelné právo
return (new FileInfo(path).Attributes & FileAttributes.Directory) == 0 &&
(new FileInfo(path).Attributes & FileAttributes.ReadOnly) == 0;
}
//process = new();
//process.StartInfo.FileName = programName;
//process.StartInfo.Arguments = arguments;
//process.StartInfo.RedirectStandardInput = true;
//process.StartInfo.RedirectStandardOutput = true;
//process.Start();
// Console.WriteLine($"{programName} -> {FindExecutableInPath(programName)}");
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = FindExecutableInPath(programName),
Arguments = arguments,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false, // Použij spíše .NET API než shell
CreateNoWindow = true // Skrytí okna konzole
};
process = new Process { StartInfo = startInfo };
process.Start();
TextWriter stdin = process.StandardInput;
var stdout = process.StandardOutput;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment