<bdo id='1M38B'></bdo><ul id='1M38B'></ul>
  • <i id='1M38B'><tr id='1M38B'><dt id='1M38B'><q id='1M38B'><span id='1M38B'><b id='1M38B'><form id='1M38B'><ins id='1M38B'></ins><ul id='1M38B'></ul><sub id='1M38B'></sub></form><legend id='1M38B'></legend><bdo id='1M38B'><pre id='1M38B'><center id='1M38B'></center></pre></bdo></b><th id='1M38B'></th></span></q></dt></tr></i><div id='1M38B'><tfoot id='1M38B'></tfoot><dl id='1M38B'><fieldset id='1M38B'></fieldset></dl></div>
  • <tfoot id='1M38B'></tfoot>

    <legend id='1M38B'><style id='1M38B'><dir id='1M38B'><q id='1M38B'></q></dir></style></legend>

      <small id='1M38B'></small><noframes id='1M38B'>

      1. 如何直接在 C# 中执行批处理命令?

        时间:2023-06-04

              <i id='r9xkl'><tr id='r9xkl'><dt id='r9xkl'><q id='r9xkl'><span id='r9xkl'><b id='r9xkl'><form id='r9xkl'><ins id='r9xkl'></ins><ul id='r9xkl'></ul><sub id='r9xkl'></sub></form><legend id='r9xkl'></legend><bdo id='r9xkl'><pre id='r9xkl'><center id='r9xkl'></center></pre></bdo></b><th id='r9xkl'></th></span></q></dt></tr></i><div id='r9xkl'><tfoot id='r9xkl'></tfoot><dl id='r9xkl'><fieldset id='r9xkl'></fieldset></dl></div>
                <bdo id='r9xkl'></bdo><ul id='r9xkl'></ul>
                <legend id='r9xkl'><style id='r9xkl'><dir id='r9xkl'><q id='r9xkl'></q></dir></style></legend>
                • <small id='r9xkl'></small><noframes id='r9xkl'>

                    <tbody id='r9xkl'></tbody>
                • <tfoot id='r9xkl'></tfoot>
                  本文介绍了如何直接在 C# 中执行批处理命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想执行一个批处理命令并将输出保存在一个字符串中,但是我只能执行该文件并且无法将内容保存在一个字符串中.

                  I want to execute a batch command and save the output in a string, but I can only execute the file and am not able to save the content in a string.

                  批处理文件:

                  @echo 关闭

                  "C:lmxendutil.exe" -licstatxml -host serv005 -port6200>C:TempHW_Lic_XML.xml 记事本 C:TempHW_Lic_XML.xml

                  "C:lmxendutil.exe" -licstatxml -host serv005 -port 6200>C:TempHW_Lic_XML.xml notepad C:TempHW_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; 
                  }
                  

                  我想要一个字符串的输出,并直接在 C# 中执行此操作而无需批处理文件,这可能吗?

                  I want the output in a string and do this directly in C# without a batch file, is this possible?

                  推荐答案

                  不需要使用CMD.exe"来执行命令行应用程序或检索输出,您可以直接使用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# 中执行批处理命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将浮点数保存为 2 个字节? 下一篇:字符串到字节[],反之亦然?

                  相关文章

                  最新文章

                    <bdo id='UZSDq'></bdo><ul id='UZSDq'></ul>
                    <tfoot id='UZSDq'></tfoot>
                    1. <small id='UZSDq'></small><noframes id='UZSDq'>

                      <i id='UZSDq'><tr id='UZSDq'><dt id='UZSDq'><q id='UZSDq'><span id='UZSDq'><b id='UZSDq'><form id='UZSDq'><ins id='UZSDq'></ins><ul id='UZSDq'></ul><sub id='UZSDq'></sub></form><legend id='UZSDq'></legend><bdo id='UZSDq'><pre id='UZSDq'><center id='UZSDq'></center></pre></bdo></b><th id='UZSDq'></th></span></q></dt></tr></i><div id='UZSDq'><tfoot id='UZSDq'></tfoot><dl id='UZSDq'><fieldset id='UZSDq'></fieldset></dl></div>

                    2. <legend id='UZSDq'><style id='UZSDq'><dir id='UZSDq'><q id='UZSDq'></q></dir></style></legend>