gpt4 book ai didi

android - C++:执行命令并返回输出导致断言失败

转载 作者:太空宇宙 更新时间:2023-11-04 12:52:21 25 4
gpt4 key购买 nike

我正在开展一个项目,该项目要求我使用 adb install 以编程方式安装 Android .apk。我还需要获取结果输出以便稍后使用。我有以下通用函数来执行命令并将输出作为字符串返回:

std::string exec(const char* command) {
std::string output = "";
const int bufferSize = 100;

FILE *pipe;
char buffer[bufferSize];

pipe = _popen(command, "r");
if (pipe == NULL) {
exit(1);
}
while (fgets(buffer, bufferSize, pipe) != NULL) {
output += buffer;
}
_pclose(pipe);

return output;
}

虽然命令执行并正确返回输出,但在使用此函数执行 adb install 时出现以下错误:

Debug Assertion Failed!

Program: ...(My .exe) File: minkernel\crts\ucrt\src\appcrt\lowio\read.cpp Line: 258

Expression: static_cast(source_buffer) == static_cast(result_buffer)

我在网上搜索了这个错误,但一无所获。以下是导致断言失败的行:

while (fgets(buffer, bufferSize, pipe) != NULL) {

谁能告诉我这是怎么回事,我可以做些什么来解决这个问题?

最佳答案

有同样的问题,并通过将模式设置为二进制(添加'b')修复:

_popen(myBuffer, "rb");

Note that only "r" is enough for Linux and MacOS, and even MSVC 2010.

Hence, seems to be yet another MSVC 2015 bug, and may be fixed in future MSVC versions.

关于android - C++:执行命令并返回输出导致断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48406142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com