0

我需要在 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 服务运行。

4

3 回答 3

0

我认为您可以尝试 /c 而不是 \c

于 2013-03-15T23:10:40.543 回答
0

这对你有用吗?

using (Process process = new Process())
{
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.FileName = @"C:\Program Files\Blacksmith\bin\apache\bin\httpd.exe";

    // Redirects the standard input so that commands can be sent to the shell.
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;

    process.OutputDataReceived += ProcessOutputDataHandler;
    process.ErrorDataReceived += ProcessErrorDataHandler;

    process.Start();
    process.BeginOutputReadLine();
    process.BeginErrorReadLine();

    process.WaitForExit();
}
于 2012-12-24T03:27:20.497 回答
0

尝试这个

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 = "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();
}
于 2012-12-24T03:33:53.503 回答