我需要在cmd上執行兩條命令。儘管我的研究,我還沒有找到一個可行的解決我的問題。首先,我需要cd到目錄,然後在該目錄中運行一個exe文件。c#通過cmd運行命令
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服務。 – jgetner