有什么办法停止_popen打开dos窗口吗? [英] Is there any way of stopping _popen opening a dos window?

查看:1629
本文介绍了有什么办法停止_popen打开dos窗口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用_popen启动一个进程来运行命令并收集输出



这是我的c ++代码:

  bool exec(string& cmd,string& result)
{
result =;

FILE * pipe = _popen(cmd.c_str(),rt);
if(!pipe)
return(false);

char缓冲区[128];
while(!feof(pipe))
{
if(fgets(buffer,128,pipe)!= NULL)
result + = buffer;
}
_pclose(pipe);
return(true);
}

有没有办法在没有dos窗口打开


解决方案

据我所知,你不能 1 :您正在启动控制台应用程序(cmd.exe,将运行指定的命令),并且Windows在启动控制台应用程序时始终创建控制台窗口。







  1. 虽然,您可以在进程启动后隐藏窗口,甚至创建它隐藏,如果你传递适当的标志到 CreateProcess ;问题是, _popen 不传递这些标志,因此您必须使用Win32 API而不是 _popen 创建您的


I am using _popen to start a process to run a command and gather the output

This is my c++ code:

bool exec(string &cmd, string &result)
{
   result = "";

   FILE* pipe = _popen(cmd.c_str(), "rt");
   if (!pipe)
      return(false);

   char buffer[128];
   while(!feof(pipe))
   {
        if(fgets(buffer, 128, pipe) != NULL)
               result += buffer;
   }
   _pclose(pipe);
   return(true);
}

Is there any way of doing this without a dos window opening (as it currently does at the _popen statement)?

解决方案

As far as I know, you can't1: you are starting a console application (cmd.exe, that will run the specified command), and Windows always creates a console window when starting a console application.


  1. although, you can hide the window after the process started, or even create it hidden if you pass the appropriate flags to CreateProcess; problem is, _popen do not pass these flags, so you have to use the Win32 APIs instead of _popen to create your pipe.

这篇关于有什么办法停止_popen打开dos窗口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆