【发布时间】:2026-01-30 11:00:02
【问题描述】:
所以我目前正在尝试从我的 ASP.NET Core MVC WebApp 启动命令提示符窗口,当我单击一个按钮时它在调试模式下运行,但由于某种原因它不会启动,除非我指定 UseShellExecute 和将其设置为 True。
这是一个问题,因为如果我将其设置为 True,我将无法重定向标准输入,这是一件坏事。 我需要能够做到这一点。
这里是代码
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 时它会起作用,并且它还会遇到断点等。
如何在不设置 UseShellExecute = True 的情况下启动 cmd 或特定批处理文件?
【问题讨论】:
-
可能是因为 cmd.exe 不在工作文件夹中。
-
嗯,使用参数来执行你需要的东西就可以了。
-
我尝试将工作目录更改为 CMD 所在的 System32 文件夹,但无法启动
-
另外,我可以运行 Notepad.exe 但不能运行 cmd.exe
标签: c# asp.net .net asp.net-core .net-core