我需要在 cmd 上执行两个命令。尽管我进行了研究,但我还没有找到可行的解决方案来解决我的问题。首先,我需要 cd 到目录,然后在该目录中运行一个 exe。
using (Process process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WorkingDirectory = @"C:\Program Files\Blacksmith\bin\apache\bin";
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = @" \c httpd.exe";
// Redirects the standard input so that commands can be sent to the shell.
process.StartInfo.RedirectStandardInput = true;
process.OutputDataReceived += ProcessOutputDataHandler;
process.ErrorDataReceived += ProcessErrorDataHandler;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
我正在尝试通过 cmd.exe 执行 httpd.exe 以阻止 apache 作为 Windows 服务运行。