将文本信息从 Windows 命令解释器 (cmd.exe) 管道到字符数组
Piping text information from the Windows command interpreter (cmd.exe) to a character array
有没有办法在不从命令解释器创建文本文件的情况下将文本信息从Windows命令解释器(cmd.exe)提取到字符数组中?
尝试_popen
( <stdio.h>
),Microsoft版本的 POSIX popen
函数:
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
FILE * pp;
char buf[1024];
string result;
if ((pp = _popen("dir", "r")) == NULL) {
return 0;
}
while (fgets(buf, sizeof(buf), pp)) {
result += buf;
}
_pclose(pp);
cout << result << endl;
return 0;
}
相关文章:
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- IPC使用多个管道和分支进程来运行Python程序
- 终端不会为C++文件创建.exe文件吗
- 在Windows中以.exe的形式运行c++
- Visual Studio mkl_link_tool.exe链接错误
- PrintWindow函数在notepad.exe中出错
- 如何创建函数管道,以便函数一个接一个地运行?
- Gstreamer 管道从命令 lne 到 c 代码
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- VSCode C++ 编译的exe感染了Win32:TrojanX-gen[Trj]
- 将返回值从 exe 传递到 bat,并将其传递给 C# 中的进程
- 获取当前正在运行的 exe 名称(不是路径)
- 将旧管道转换为现代 openGL 时出现问题
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 无法读取在cmd.exe管道下启动的进程的输出
- CreateProcess cmd.exe读/写管道死锁
- 将PowerShell.exe的输入和输出重定向到C 中的管道
- 使用管道.exe wmic 的输出重定向
- 将文本信息从 Windows 命令解释器 (cmd.exe) 管道到字符数组