为什么不将ShellExecute设置为true就不能启动进程?

时间:2019-12-12 15:06:48

标签: c# asp.net .net asp.net-core .net-core

因此,我当前正在尝试从我的ASP.NET Core MVC WebApp启动命令提示符窗口,当单击按钮时,该窗口在调试模式下运行,但由于某种原因,除非我指定{{1} }并将其设置为True。

这是一个问题,因为如果我将其设置为True,则无法重定向标准输入,这是一件坏事。 我需要能够做到这一点。

这是代码

UseShellExecute

它确实会调用代码,因为请记住,它在我执行public static void Start(string dirPath) { Process serverProcess = new Process { StartInfo = { CreateNoWindow = false, FileName = "cmd.exe", Arguments = "", WindowStyle = ProcessWindowStyle.Maximized, RedirectStandardInput = true } }; serverProcess.Start() } 时会起作用,并且还会遇到断点等。

如何在不设置UseShellExecute = True的情况下启动cmd或特定的批处理文件?

1 个答案:

答案 0 :(得分:1)

UseShellExecute对于Core默认为false。如果您不想设置UseShellExecute。尝试将下面的Arguments设置为解决方法:

Arguments = $"/c start cmd.exe", 

参考:https://github.com/dotnet/corefx/issues/21767