我有一个音频转换器 .exe,我想将它封装在 C# 程序中,用于 UI 和输入等。要使用 AudioConverter.exe,它是从带有后缀“< inputFile > ouputFile”的控制台运行的。所以整行读起来像
C:\\User\Audioconverter.exe < song.wav > song.ogg
到目前为止,我已经能够在 C# 之外成功启动转换器,我已经设法通过 C# 中的创建进程在挂起状态下运行转换器(没有输入和输出文件)。到目前为止,我在 C# 中的代码与此站点上给出的答案非常相似:
using System;
using System.Diagnostics;
namespace ConverterWrapper2
{
class Program
{
static void Main()
{
LaunchCommandLineApp();
}
static void LaunchCommandLineApp()
{
// For the example
const string ex1 = "C:\\Users\\AudioConverter.exe";
const string ex2 = "C:\\Users\\res\\song.wav";
const string ex3 = "C:\\Users\\out\\song.ogg";
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "AudioConverter2.exe";
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.Arguments = ex1 + " < " + ex2 + " > " + ex3; \\Process is ran successfully without the addition of input and output files, but hangs waiting for files.
try
{
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}
}
}
}
到目前为止,转换器 exe 无法正确启动,这让我问这个问题是标准输入的输入与参数不同吗?
无论如何,我都需要模仿这种输入方式,并且会很感激任何信息。我曾假设我可以将输入和输出文件作为参数传递,但我运气不佳。