windows 如何从没有控制台窗口的 C/C++ 执行批处理文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6671410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:24:39  来源:igfitidea点击:

how to execute batch file from C/C++ w/o console window?

c++cwindowsbatch-fileconsole

提问by Andriy Tylychko

I'm executing batch file from a C++ program by system("start /B mybatch.bat")call, where /Bis supposed to run batch file w/o console window. But it's still visible.

我正在通过system("start /B mybatch.bat")调用从 C++ 程序执行批处理文件,/B应该在没有控制台窗口的情况下运行批处理文件。但它仍然可见。

Edit: I resolved the issue by ShellExecute()as was proposed in comments

编辑:我ShellExecute()按照评论中的建议解决了这个问题

回答by ?lex

Why don't you use CreateProcess instead ?

为什么不使用 CreateProcess 呢?

回答by SKrat

On Windows, if you don't use Windows Runtime, you can try _popenor _wpopen: MSDN.

在 Windows 上,如果您不使用 Windows 运行时,您可以尝试_popen_wpopen: MSDN

I used it mainly because _popencreates a pipe so I can easily read output as well.

我使用它主要是因为_popen创建了一个管道,因此我也可以轻松读取输出。