【发布时间】:2021-07-08 22:56:50
【问题描述】:
我有一个音频转换器 .exe,我想将它封装在 C# 程序中,用于 UI 和输入等。 要使用 AudioConverter.exe,它从控制台运行,后缀为“ 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 还不能正确启动,这让我问这个问题是标准输入的输入与参数不同吗?
不管我需要模仿这种输入方式,并且会感谢任何信息。我曾以为我可以将输入和输出文件作为参数传递,但我运气不佳。
【问题讨论】: