是否可以使用参数运行.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.
}
}