【发布时间】:2012-12-24 03:16:52
【问题描述】:
我需要在 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 服务运行。
【问题讨论】:
-
您是想通过 httpd.exe 获得命令提示符,还是只是想执行 httpd.exe?
-
我只是想通过 cmd.exe 执行 httpd.exe 来阻止 apache 成为 windows 服务。
-
是啊,你为什么不直接开始
httpd.exe? -
因为将 apache 作为服务运行
-
你不能同时使用 shell 和重定向。