We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
这是一个函数,具体功能是获取硬盘的序列号,但是只能输出,并不能存储下来,具体的是使用shell的system()函数进行操作,关键语句是: snprintf(command, sizeof(command), "sudo hdparm -i %s | grep SerialNo > %s | tee -a 2.log", disk_name.c_str(), hdparm_result); //将命令写入commond中 num=system(command); //调用system()函数,屏幕输出硬盘序列号
函数代码: static bool get_disk_serial_by_way_3(const std::string & disk_name,std::string & serial_no) { int num; printf("\n--------------6---------------\n"); serial_no.c_str(); const char * hdparm_result = ".hdparm_result.txt"; char command[512] = { 0 }; snprintf(command, sizeof(command), "sudo hdparm -i %s | grep SerialNo > %s | tee -a 2.log", disk_name.c_str(), hdparm_result); num=system(command); printf("the value of system is %d.\n",num); if (0 == system(command))//Judge function system() whether come into effect {
get_serial(hdparm_result, "SerialNo=", serial_no); } unlink(hdparm_result); return(!serial_no.empty());
}
问了一些人,有人说将commond的内容改成 sudo hdparm -i %s | grep SerialNo > %s | tee -a 2.log 即将信息写入到2.log文本,然后通过读取2.log文本来实现读取存储到序列号来
The text was updated successfully, but these errors were encountered:
help!help!help!很急
Sorry, something went wrong.
No branches or pull requests
这是一个函数,具体功能是获取硬盘的序列号,但是只能输出,并不能存储下来,具体的是使用shell的system()函数进行操作,关键语句是:
snprintf(command, sizeof(command), "sudo hdparm -i %s | grep SerialNo > %s | tee -a 2.log", disk_name.c_str(), hdparm_result); //将命令写入commond中
num=system(command); //调用system()函数,屏幕输出硬盘序列号
函数代码:
static bool get_disk_serial_by_way_3(const std::string & disk_name,std::string & serial_no)
{
int num;
printf("\n--------------6---------------\n");
serial_no.c_str();
const char * hdparm_result = ".hdparm_result.txt";
char command[512] = { 0 };
snprintf(command, sizeof(command), "sudo hdparm -i %s | grep SerialNo > %s | tee -a 2.log", disk_name.c_str(), hdparm_result);
num=system(command);
printf("the value of system is %d.\n",num);
if (0 == system(command))//Judge function system() whether come into effect
{
}
问了一些人,有人说将commond的内容改成
sudo hdparm -i %s | grep SerialNo > %s | tee -a 2.log 即将信息写入到2.log文本,然后通过读取2.log文本来实现读取存储到序列号来
The text was updated successfully, but these errors were encountered: