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

时间:2016-10-17 13:34:39

标签: c# asp.net-web-api asp.net-core ipc .net-core

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

我尝试将ConsoleApp1.exe放入项目根文件夹并从Controller调用LaunchCommandLineApp,但它不起作用: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.
    }
}

enter image description here

0 个答案:

没有答案