xml - How I can execute a Batch Command in C# directly? -
hi have question c# , batch files. want execute batch command , save output in string in c#. can execute file not save content in string , show in textbox.
my batch file:
@echo off
"c:\lmxendutil.exe" -licstatxml -host serv005 -port 6200>c:\temp\hw_lic_xml.xml notepad c:\temp\hw_lic_xml.xml
here c# code:
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 output *** processinfo.redirectstandarderror = true; processinfo.redirectstandardoutput = true; process = process.start(processinfo); process.waitforexit(); // *** read streams *** string output = process.standardoutput.readtoend(); string error = process.standarderror.readtoend(); exitcode = process.exitcode; process.close(); return output; }
i want output stirng , if can want not have batch file. want batvchcommand direct in c# ...can this?
don't need use "cmd.exe" execute commandline application or retreive output, can use "lmxendutil.exe" directly.
try this:
processinfo = new processstartinfo(); processinfo.filename = "c:\\lmxendutil.exe"; processinfo.arguments = "-licstatxml -host serv005 -port 6200"; //etc...
do modifications use "command" there.
i hope helps.
Comments
Post a Comment