有没有一种方法可以像使用c#一样运行CMD命令,而不将其拆分为文件名和参数?

有没有一种方法可以像使用c#一样运行CMD命令,而不将其拆分为文件名和参数?,c#,cmd,process,freeze,C#,Cmd,Process,Freeze,我正在开发一个用命令解析文件的软件,它需要执行所有命令。 查找Hourgh StackOverFlow,我发现了以下代码段: String command = @".\wrap.exe sys"; using (Process myProcess = new Process()) { myProcess.StartInfo.UseShellExecute = false; // You can start any process, HelloWorld is a do-nothi

我正在开发一个用命令解析文件的软件,它需要执行所有命令。 查找Hourgh StackOverFlow,我发现了以下代码段:

String command = @".\wrap.exe sys";
using (Process myProcess = new Process())
{
    myProcess.StartInfo.UseShellExecute = false;
    // You can start any process, HelloWorld is a do-nothing example.
    myProcess.StartInfo.RedirectStandardOutput = true;
    myProcess.StartInfo.FileName = "CMD.exe";
    myProcess.StartInfo.CreateNoWindow = true;
    myProcess.StartInfo.Arguments = command; 
    myProcess.Start();
    string output = myProcess.StandardOutput.ReadToEnd();
    myProcess.WaitForExit();

}
由于某种原因,如果我运行命令
myProcess.StandardOutput.ReadToEnd()
,该命令将挂起(即使我更改了该命令的顺序,并且该命令
myProcess.WaitForExit()
和标准错误输出命令也将挂起)(知道该命令挂起的原因吗?)

如果我将
FileName=“CMD.exe”
更改为
FileName=“wrap.exe”
Arguments=“sys”
,它就会工作。
问题是,我不想将其拆分为参数和文件名。有没有办法(例如,在Python中使用子进程)?

您是否尝试在
wrap.exe
之前添加
/c
?这是否回答了您的问题?@PavelAnikhouski没有help@Magnetron不,没有。我在发帖之前看过了