mirror of https://github.com/Radarr/Radarr
Fixed: Executing powershell and python scripts directly in Connect->Custom Scripts
This commit is contained in:
parent
6c84518b40
commit
ae47ee817f
|
@ -87,6 +87,54 @@ namespace NzbDrone.Common.Test
|
||||||
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse();
|
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Should_be_able_to_start_powershell()
|
||||||
|
{
|
||||||
|
WindowsOnly();
|
||||||
|
|
||||||
|
var tempDir = GetTempFilePath();
|
||||||
|
var tempScript = Path.Combine(tempDir, "myscript.ps1");
|
||||||
|
|
||||||
|
Directory.CreateDirectory(tempDir);
|
||||||
|
|
||||||
|
File.WriteAllText(tempScript, "Write-Output 'Hello There'\r\n");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = Subject.StartAndCapture(tempScript);
|
||||||
|
|
||||||
|
result.Standard.First().Content.Should().Be("Hello There");
|
||||||
|
}
|
||||||
|
catch (Win32Exception ex) when (ex.NativeErrorCode == 2)
|
||||||
|
{
|
||||||
|
Assert.Fail("No Powershell available?!?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Should_be_able_to_start_python()
|
||||||
|
{
|
||||||
|
WindowsOnly();
|
||||||
|
|
||||||
|
var tempDir = GetTempFilePath();
|
||||||
|
var tempScript = Path.Combine(tempDir, "myscript.py");
|
||||||
|
|
||||||
|
Directory.CreateDirectory(tempDir);
|
||||||
|
|
||||||
|
File.WriteAllText(tempScript, "print(\"Hello There\")\r\n");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = Subject.StartAndCapture(tempScript);
|
||||||
|
|
||||||
|
result.Standard.First().Content.Should().Be("Hello There");
|
||||||
|
}
|
||||||
|
catch (Win32Exception ex) when (ex.NativeErrorCode == 2)
|
||||||
|
{
|
||||||
|
Assert.Inconclusive("No Python available");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Ignore("Shit appveyor")]
|
[Ignore("Shit appveyor")]
|
||||||
|
|
|
@ -365,6 +365,16 @@ namespace NzbDrone.Common.Processes
|
||||||
return ("cmd.exe", $"/c {path} {args}");
|
return ("cmd.exe", $"/c {path} {args}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OsInfo.IsWindows && path.EndsWith(".ps1", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
return ("powershell.exe", $"-ExecutionPolicy Bypass -NoProfile -File {path} {args}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OsInfo.IsWindows && path.EndsWith(".py", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
return ("python.exe", $"{path} {args}");
|
||||||
|
}
|
||||||
|
|
||||||
return (path, args);
|
return (path, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue