Почему идентификатор popen не определён, если он определяется в <cstdio>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
const char* ATA_COMMAND = "atacmd";
const char* ATA_USB_2_0_COMMAND = "-d sat,12";
const char* ATA_USB_3_0_COMMAND = "-d sat,13";
const char* ATA_SATA_COMMAND = "-d sat";
const char* ATA_IDENTIFY_COMMAND = "-i";
bool executeCommand(const std::string& command, std::vector<std::string>& output) {
char buffer[128];
std::string result = "";
FILE* pipe = popen(command.c_str(), "r");
if (!pipe) return false;
while (!feof(pipe)) {
if (fgets(buffer, 128, pipe) != nullptr) {
result += buffer;
}
}
pclose(pipe);
output.push_back(result);
return true;
}
int main() {
std::vector<std::string> output;
if (!executeCommand(std::string(ATA_COMMAND) + " " + ATA_IDENTIFY_COMMAND + " " + ATA_SATA_COMMAND, output)) {
std::cout << "Ошибка выполнения команды" << std::endl;
return 1;
}
bool isUSB = false;
bool isUSB3 = false;
bool isSSD = false;
for (const auto& line : output) {
if (line.find("Transport: Serial ATA") != std::string::npos) {
isUSB = false;
isUSB3 = false;
}
else if (line.find("Transport: USB") != std::string::npos) {
isUSB = true;
if (line.find("SATA Gen3") != std::string::npos) {
isUSB3 = true;
}
}
else if (line.find("Rotation Rate:") != std::string::npos) {
if (line.find("Solid State Device") != std::string::npos) {
isSSD = true;
}
}
}
if (isUSB) {
if (isUSB3) {
std::cout << "USB 3.0" << std::endl;
}
else {
std::cout << "USB 2.0" << std::endl;
}
std::cout << "SATA" << std::endl;
}
else {
std::cout << "SATA" << std::endl;
if (isSSD) {
std::cout << "SSD" << std::endl;
}
else {
std::cout << "HDD" << std::endl;
}
}
return 0;
}
По задумке здесь должны отличаться типы дисковых носителей, но из за невозможности использовать popen/pclose, задумка не осуществляется
Источник: Stack Overflow на русском