コマンド/dev
のようなパス名を指定して、対応するファイルを取得しようとしていますdf
system()
私は現在このコマンドを使用していますが、関数やシステム固有のコマンドは使用したくありません。
現在のコードは次のとおりです。
const string PathStr (Path); // Path is input value
// get the /dev/* files
string Cmd ("df 2> /dev/null | grep /dev | awk '{print $1, $6}'");
FILE * Pipe = popen (Cmd.c_str(), "r");
if (!Pipe)
{
errorLog("Cannot execute command : \"" + Cmd + '"');
return string();
}
char Buf [BufSz];
stringstream sstr;
while (!feof(Pipe))
{
if (fgets(Buf, BufSz, Pipe))
sstr << Buf;
}
pclose(Pipe);
// get the actual /dev file
pair<string, string> DiskPaths;
while (!sstr.eof())
{
string Dev, MountPoint;
sstr >> Dev >> MountPoint;
if (string::npos != PathStr.find(MountPoint) &&
MountPoint.size() > DiskPaths.second.size())
DiskPaths = make_pair(Dev, MountPoint);
}