Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Engines: give the programs Filee starts an empty input

KnifeLemonccb825618139
diff --git a/src/Filee.Engines/Infrastructure/ProcessRunner.cs b/src/Filee.Engines/Infrastructure/ProcessRunner.cs
index f991d2ca..55297a81 100644
--- a/src/Filee.Engines/Infrastructure/ProcessRunner.cs
+++ b/src/Filee.Engines/Infrastructure/ProcessRunner.cs
@@ -45,6 +45,9 @@ public static class ProcessRunner
{
UseShellExecute = false,
CreateNoWindow = true,
+ // Closed right after the start: a program that asks a question (7-Zip's password prompt) reads end of
+ // input instead of waiting on the console or pipe Filee itself was started with.
+ RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
StandardOutputEncoding = Encoding.UTF8,
@@ -67,6 +70,7 @@ public static class ProcessRunner
if (!process.Start())
throw new InvalidOperationException($"Could not start {executable}.");
Lower(process);
+ process.StandardInput.Close();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
diff --git a/tests/Filee.Engines.Tests/AppLocalRuntimeTests.cs b/tests/Filee.Engines.Tests/AppLocalRuntimeTests.cs
index 3fe83316..32f59e3e 100644
--- a/tests/Filee.Engines.Tests/AppLocalRuntimeTests.cs
+++ b/tests/Filee.Engines.Tests/AppLocalRuntimeTests.cs
@@ -48,6 +48,19 @@ public sealed class AppLocalRuntimeTests : IDisposable
Assert.Equal(3, ordinary.ExitCode);
}
+ [Fact]
+ public async Task ProcessRunner_gives_a_program_that_reads_input_an_empty_input()
+ {
+ Assert.SkipUnless(OperatingSystem.IsWindows(), "cmd.exe.");
+ var cmd = Path.Combine(Environment.SystemDirectory, "cmd.exe");
+
+ // "set /p" waits for a line; with Filee's own input passed on it would wait until the timeout.
+ var result = await ProcessRunner.RunAsync(cmd, ["/c", "set /p answer=Password? & exit 4"], TimeSpan.FromSeconds(30),
+ TestContext.Current.CancellationToken);
+
+ Assert.Equal(4, result.ExitCode);
+ }
+
[Fact]
public void LibreOffice_gets_its_own_runtime_next_to_soffice()
{