【发布时间】:2023-04-03 18:05:02
【问题描述】:
好的,这是我想调用在 \windows\system32\wbem 中找到的 wmic.exe 执行命令并仅从那里读取输出的问题。
我不想按照 msdn (http://msdn.microsoft.com/en-us/library/aa390423(v=vs.85).aspx) 使用 com 使用 wmi,也不想通过 cmd 执行 wmic。
我无法让它发挥作用。我也读过这个帖子,但没有人回答non-trivial use of `Console` by `wmic.exe`
我尝试过这样的事情:
FILE* pipe = _popen("wmic.exe cpu get", "r");
if (!pipe)
throw std::exception("error");
char buffer[128];
std::string output;
while(!feof(pipe))
{
if(fgets(buffer, 128, pipe) != NULL) output += buffer;
}
_pclose(pipe);
std::stringstream oss(output);
std::vector<std::string> processor_description;
std::string buffer;
while (std::getline(oss, buffer))
processor_description.push_back(buffer);
【问题讨论】:
-
我尝试使用管道(_popen 和 _pclose)
-
我已经把你的源代码贴在问题里了,请下次自己做
-
好的,抱歉!关于我的问题有什么想法吗? <:>
-
我也发现了这个帖子stackoverflow.com/questions/25935739/wmic-to-get-info-in-qt 但没有回答(使用qt creator)
-
为什么不使用 Microsoft 的工作 COM 示例?
标签: c++ visual-studio-2010 visual-studio visual-c++ wmic