parse percentage from shred cmd

This commit is contained in:
2020-08-22 21:48:34 +02:00
parent df4ed53693
commit e4b3923f6d
7 changed files with 94 additions and 106 deletions

57
src/shred.cpp Normal file
View File

@ -0,0 +1,57 @@
/**
* @file shred.cpp
* @brief shred drive
* @author hendrik schutter
* @date 03.05.2020
*/
#include "../include/reHDD.h"
/**
* \brief shred drive with shred
* \param pointer of Drive instance
* \return void
*/
void Shred::shredDrive(Drive* drive)
{
size_t len = 0; //lenght of found line
char* cLine = NULL; //found line
#ifndef DRYRUN
string sCMD = ("shred -v ");
sCMD.append(drive->getPath());
#endif
#ifdef DRYRUN
cout << "dryrun for " << drive->getPath() << endl;
// string sCMD = ("ping ::1 -c 5");
string sCMD = ("bash shred_dummy.sh");
#endif
const char* cpComand = sCMD.c_str();
cout << "shred: " << cpComand << endl;
FILE* shredCmdOutput = popen(cpComand, "r");
while ((getline(&cLine, &len, shredCmdOutput)) != -1)
{
string sLine = string(cLine);
// TODO parse percentage
string search("%");
size_t found = sLine.find(search);
if (found!=string::npos){
uint8_t percent = 0U;
sLine.erase(0, sLine.find("%")-2);
sLine.erase(std::remove(sLine.begin(), sLine.end(), '\n'), sLine.end());
int i = std::stoi(sLine);
cout << i << " percent" << endl;
}
}
fclose(shredCmdOutput);
}