안녕 나는 C# 및 배치 파일에 대한 질문이 있습니다. 배치 명령을 실행하고 C#의 문자열에 출력을 저장하고 싶습니다. 하지만 난 단지 파일을 실행할 수 있지만 문자열에이 내용을 저장하고 텍스트 상자에 표시하지 않습니다. C#에서 일괄 처리 명령을 어떻게 직접 실행할 수 있습니까?
내 배치 파일 :오프 @echo
"C : \ lmxendutil.exe"-licstatxml -host serv005 -port 6200> C : \ 임시 \의 HW_Lic_XML.xml 메모장 C : \ 임시 \ HW_Lic_XML.xml 여기
내 C# 코드 :
private void btnShowLicstate_Click(object sender, EventArgs e)
{
string command = "'C:\\lmxendutil.exe' -licstatxml -host lwserv005 -port 6200";
txtOutput.Text = ExecuteCommand(command);
}
static string ExecuteCommand(string command)
{
int exitCode;
ProcessStartInfo processInfo;
Process process;
processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
// *** Redirect the output ***
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
process = Process.Start(processInfo);
process.WaitForExit();
// *** Read the streams ***
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
exitCode = process.ExitCode;
process.Close();
return output;
}
나는 출력을 원한다. 내가 이것을 할 수 있다면 나는 배치 파일이 없다고 원한다. 나는이 batvchcommand를 C#에서 직접하고 싶다. 내가 할 수 있을까?
http://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp – Rahul
내 업데이트를보세요 ... – Tarasov