<bdo id='HXOzX'></bdo><ul id='HXOzX'></ul>

    <small id='HXOzX'></small><noframes id='HXOzX'>

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

        <legend id='HXOzX'><style id='HXOzX'><dir id='HXOzX'><q id='HXOzX'></q></dir></style></legend>

      1. C++ 执行 CMD 命令

        时间:2023-08-01

            <small id='i7Xlg'></small><noframes id='i7Xlg'>

              <bdo id='i7Xlg'></bdo><ul id='i7Xlg'></ul>
              <tfoot id='i7Xlg'></tfoot>

                <legend id='i7Xlg'><style id='i7Xlg'><dir id='i7Xlg'><q id='i7Xlg'></q></dir></style></legend>
                  <tbody id='i7Xlg'></tbody>
                <i id='i7Xlg'><tr id='i7Xlg'><dt id='i7Xlg'><q id='i7Xlg'><span id='i7Xlg'><b id='i7Xlg'><form id='i7Xlg'><ins id='i7Xlg'></ins><ul id='i7Xlg'></ul><sub id='i7Xlg'></sub></form><legend id='i7Xlg'></legend><bdo id='i7Xlg'><pre id='i7Xlg'><center id='i7Xlg'></center></pre></bdo></b><th id='i7Xlg'></th></span></q></dt></tr></i><div id='i7Xlg'><tfoot id='i7Xlg'></tfoot><dl id='i7Xlg'><fieldset id='i7Xlg'></fieldset></dl></div>
                • 本文介绍了C++ 执行 CMD 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在这里遇到了一个严重的问题.我需要通过 C++ 执行 CMD 命令行而不显示控制台窗口.因此我不能使用 system(cmd),因为窗口会显示.

                  I'm having a serious problem here. I need to execute a CMD command line via C++ without the console window displaying. Therefore I cannot use system(cmd), since the window will display.

                  我已经尝试过 winExec(cmd, SW_HIDE),但这也不起作用.CreateProcess 是我尝试过的另一个.但是,这是用于运行程序或批处理文件.

                  I have tried winExec(cmd, SW_HIDE), but this does not work either. CreateProcess is another one I tried. However, this is for running programs or batch files.

                  我最终尝试了 ShellExecute:

                  ShellExecute( NULL, "open",
                      "cmd.exe",
                      "ipconfig > myfile.txt",
                      "c:projects",
                      SW_SHOWNORMAL
                  );
                  

                  有人能看出上面的代码有什么问题吗?我一直在使用 SW_SHOWNORMAL 直到我知道它有效.

                  Can anyone see anything wrong with the above code? I have used SW_SHOWNORMAL until I know this works.

                  我真的需要一些帮助.什么都没有发现,我已经尝试了很长一段时间.任何人都可以提供的任何建议都会很棒:)

                  I really need some help with this. Nothing has come to light, and I have been trying for quite a while. Any advice anyone could give would be great :)

                  推荐答案

                  将输出重定向到您自己的管道是一个更简洁的解决方案,因为它避免了创建输出文件,但这工作正常:

                  Redirecting the output to your own pipe is a tidier solution because it avoids creating the output file, but this works fine:

                  ShellExecute(0, "open", "cmd.exe", "/C ipconfig > out.txt", 0, SW_HIDE);
                  

                  您没有看到 cmd 窗口,并且输出按预期重定向.

                  You don't see the cmd window and the output is redirected as expected.

                  您的代码可能失败了(除了 /C 之外),因为您将路径指定为 "c:projects" 而不是 "c:\projects\b".

                  Your code is probably failing (apart from the /C thing) because you specify the path as "c:projects" rather than "c:\projects\b".

                  这篇关于C++ 执行 CMD 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:CreateProcess 不传递命令行参数 下一篇:如何在没有清单的情况下启用视觉样式

                  相关文章

                  最新文章

                  <tfoot id='1Myw0'></tfoot>

                • <small id='1Myw0'></small><noframes id='1Myw0'>

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

                      • <bdo id='1Myw0'></bdo><ul id='1Myw0'></ul>