aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Integrations/Scripts
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-10-26 18:27:34 -0500
committerJP Dillingham <jp@dillingham.me>2024-10-26 18:27:34 -0500
commit334627cd06476df897cf3f3ec02ca70b51b7fec1 (patch)
treee8ced369b7631ef46d3043118aac5518dca76d35 /src/slskd/Integrations/Scripts
parentb2c01f2bfb1b7ae910ee52554a973cad3a71171a (diff)
downloadslskd-334627cd06476df897cf3f3ec02ca70b51b7fec1.tar.gz
allow one-word scripts
Diffstat (limited to 'src/slskd/Integrations/Scripts')
-rw-r--r--src/slskd/Integrations/Scripts/ScriptService.cs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/slskd/Integrations/Scripts/ScriptService.cs b/src/slskd/Integrations/Scripts/ScriptService.cs
index 4e086148..48916b2d 100644
--- a/src/slskd/Integrations/Scripts/ScriptService.cs
+++ b/src/slskd/Integrations/Scripts/ScriptService.cs
@@ -67,10 +67,18 @@ public class ScriptService
try
{
- // todo: update options validation to ensure run strings have at least 2 words
var run = script.Value.Run;
- var executable = run.Split(" ", 2)[0];
- var args = run.Split(" ", 2)[1].Replace("$DATA", data.ToJson());
+
+ // split the string into at most 2 parts, leaving part [0] the executable and part [1] the rest of the string, but possibly null
+ var parts = run.Split(" ", count: 2, options: StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.RemoveEmptyEntries);
+
+ var executable = parts[0];
+ string args = default;
+
+ if (parts.Length > 1)
+ {
+ args = parts[1].Replace("$DATA", data.ToJson());
+ }
Log.Debug("Running script '{Script}': {Run}", script.Key, run);
var sw = Stopwatch.StartNew();
@@ -87,7 +95,12 @@ public class ScriptService
};
process.Start();
- process.StandardInput.WriteLine($"{args}");
+
+ if (args is not null)
+ {
+ process.StandardInput.WriteLine(args);
+ }
+
process.StandardInput.WriteLine("exit");
process.WaitForExit();