使用_Popen Windows时问题
Issue when using _popen windows
你好,我尝试使用_popen运行执行Windows命令,其工作在Console的VC 中正常。
虽然我在C 构建器中使用的代码相同的代码vcl表格popen return null指针?
vc
std::string exec(const char* cmd) {
char buffer[128];
std::string result = "";
FILE* pipe = _popen(cmd, "r");
if (!pipe) throw std::runtime_error("popen() failed!");
try {
while (!feof(pipe)) {
if (fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
}
catch (...) {
_pclose(pipe);
throw;
}
_pclose(pipe);
return result;
}
c 建筑商与上述相同
void __fastcall TForm2::btn_adb_readInfoClick(TObject *Sender) {
const char* cmd = "D:\adb\adb.exe devices";
char buffer[128];
std::string result = "";
FILE* pipe = _popen(cmd, "r"); // always null
char* er = strerror(errno);
try
{
if (!pipe) throw std::runtime_error("popen() failed!");
while (!feof(pipe)) {
if (fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
}
catch (std::exception &ex) {
_pclose(pipe);
throw;
}
_pclose(pipe);
}
_popen
状态的MSDN文档:
如果在Windows程序中使用,则
_popen
功能返回无效的 文件指针导致程序无限期停止响应。_popen
在控制台应用程序中正常工作。
我假设C 构建器正在创建Windows应用程序而不是控制台应用程序。
相关文章:
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- 使用 MinGW 在 Windows 上构建 GLEW 时遇到问题
- 父进程意外被子 cmd 杀死.exe运行 java jar 的进程 - WINDOWS 7 问题 - C++
- 在 Windows 服务中使用命名管道时出现问题
- 在 Windows 10 上安装 Boost 时遇到问题
- CMake Qt建立在Windows链接器问题之上
- C++ Windows.h 的问题,在 vs17 中非法声明匿名'struct'
- 在 Windows 问题上连接到企业 WiFi
- C++、Python 3.7.4、SWIG 4.0.0 和 Windows 10 的问题 - ModuleNotFoun
- Windows 凭据提示问题,CredUnPackAuthenticationBuffer 错误 50
- 使用 Bazel (Windows) 构建 Tensorflow 的问题 => 使用 Tensorflow C++ API
- 显示和隐藏Windows 10屏幕键盘(osk.exe)时遇到问题
- 在 Windows 上使用 Emscripten 和 CMake 编译 GLFM 的问题
- 为什么我的C 代码在Linux上运行,而在Windows上不运行,是否有RAM内存的问题
- 在 Visual Studio 的 Windows 上安装 MPIR 时遇到问题
- 将Qt Creator Projet移植到Windows时的z.lib问题
- 问题:Windows 10:QMYSQL驱动程序未加载
- 自旋控制位置问题(Windows)
- 通过无线互联网连接保持长期持续的套接字连接问题Windows
- 使用什么Qt GUI容器?还有相关的视频显示问题- Windows 7