Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
I3csstatus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
I3csstatus
Commits
91bc1e15
Commit
91bc1e15
authored
8 months ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Fix exec pouze z $PATH a ne .
parent
89948bd8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Module.cs
+55
-5
55 additions, 5 deletions
Module.cs
with
55 additions
and
5 deletions
Module.cs
+
55
−
5
View file @
91bc1e15
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment