C# - 使用参数启动应用程序。

C# - Launch application with arguments.

您好,我要启动软件 CFast 进行参数分析。为此,我想在 C# 中创建一个 运行 是核心 CFast.exe 的应用程序。如果我想要 运行 来自 cmd.exe 的软件并在文件 INPUTFILENAME.in 上执行它,我会在提示符中写入:

CFast.exe INPUTFILENAME

我在 C# 中编写了以下代码:

Process firstProc = new Process();
firstProc.StartInfo.FileName = @"C:\Users\Alberto\Desktop\Simulazioni Cfast\D\C\N\A3B1\CFAST.exe";
firstProc.StartInfo.Arguments = @"INPUTFILENAME";
firstProc.EnableRaisingEvents = true;
firstProc.Start();
firstProc.WaitForExit();

使用此代码 CFast 运行 但不分析任何内容...似乎不接受该论点。提示这个麻烦?

已解决。文件名和命令语法错误

// setup cmd process
        var command = @"CFAST.exe C:\Users\Alberto\Desktop\Simulazioni_Cfast\D\C\N\A3B1\A3B1";
        ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;
        procStartInfo.RedirectStandardError = true;
        procStartInfo.CreateNoWindow = true;

        // start process
        Process proc = new Process();
        proc.StartInfo = procStartInfo;
        proc.Start();

        proc.WaitForExit();

        // read process output
        string cmdError = proc.StandardError.ReadToEnd();
        string cmdOutput = proc.StandardOutput.ReadToEnd();

其中 A3B1 是 .IN 文件的名称