我怎么能执行在C#中直接一个批处理命令?

编程入门 行业动态 更新时间:2024-10-11 15:14:04
本文介绍了我怎么能执行在C#中直接一个批处理命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我有C#和批处理文件的问题。我想不执行批处理命令和输出保存到C#中的字符串。但我只能执行该文件,但不是在一个字符串保存此内容,并显示在这一个文本框。

hi i have a question to c# and batch files. I want do execute a batch command and save the output in a string in c#. but i can only execute the file but not save this content in a string and show this in a textbox.

我的批处理文件:

关闭@echo

C:\\ lmxendutil.exe-licstatxml -host serv005 -port  6200> C:\\ TEMP \\ HW_Lic_XML.xml记事本C:\\ TEMP \\ HW_Lic_XML.xml

"C:\lmxendutil.exe" -licstatxml -host serv005 -port 6200>C:\Temp\HW_Lic_XML.xml notepad C:\Temp\HW_Lic_XML.xml

下面是我的C#code:

Here is my 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 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; }

我要输出I A stirng,如果我能做到这一点,我想,我没有一个批处理文件。我想这样做batvchcommand直接在C#...我能做到这一点?

I want the output i a stirng and if i can do this i want that i not have a batch file. i want do this batvchcommand direct in c# ...can i do this?

推荐答案

不需要用的CMD.exe用于执行命令行应用程序或retreive输出,可以用lmxendutil.exe直接。

Don't need to use "CMD.exe" for execute a commandline application or retreive the output, you can use "lmxendutil.exe" directly.

试试这个:

processInfo = new ProcessStartInfo(); processInfo.FileName = "C:\\lmxendutil.exe"; processInfo.Arguments = "-licstatxml -host serv005 -port 6200"; //etc...

做你的修改,用命令在那里。

Do your modifications to use "command" there.

我希望这有助于。

更多推荐

我怎么能执行在C#中直接一个批处理命令?

本文发布于:2023-11-02 18:19:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553083.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中直   批处理   接一个   命令   我怎么能

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!