如何从自托管的asp.net-core应用程序调用可执行文件?

nic*_*cks 6 c# ipc asp.net-web-api .net-core asp.net-core

是否可以.exe使用参数运行文件并从asp.net-core自托管应用程序接收返回值?如果是 - 如何?

我尝试放入ConsoleApp1.exe项目根文件夹并LaunchCommandLineApp从Controller 调用,但它不起作用:exeProcess填充错误的属性

static void LaunchCommandLineApp()
{
    // For the example.
    const string ex1 = "C:\\";
    const string ex2 = "C:\\Dir";

    // Use ProcessStartInfo class.
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.FileName = "ConsoleApp1.exe";
    //startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;

    try
    {
        // Start the process with the info we specified.
        // Call WaitForExit and then the using-statement will close.
        using (Process exeProcess = Process.Start(startInfo))
        {
            exeProcess.WaitForExit();
        }
    }
    catch (Exception ex)
    {
        // Log error.
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述