Question : How to catch exception of system command.

Hey Experts.
I made this code on C++ to delete all the files, with the extension I choose, in a directory.
I'm on Linux Red Hat and I'm using the system commando to delete the files.
The thing I want to know is how can I catch the exceptions of the system command?

The code, the way it is now, delete the .log files in the directory specified but when it hits the files that aren't with the .log extension, the program show me this error:
rm: impossible to remove `/home/pablo/testee/*.log': File not found.

Like I said everything works fine, but the exception handling I used in this code doesn't prevent these error messages from showing. How can I do that?

The code is attached.
Thanks in advance.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
#include <fstream>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string>
#include <cstdio>
#include <exception>

using namespace std;

int main ()
{
    string file;
    char result;
    const string path = "/home/pablo/testee";

    DIR* dir = opendir(path.c_str());
    struct dirent* ent = 0;

    while (dir && (ent = readdir(dir))) 
    {
          try
          {
          system ("rm /home/pablo/testee/*.log");
          }
          catch (exception& e){}
    }

    closedir(dir);
    
    return 0;
}

Answer : How to catch exception of system command.

Don't use the system command to do this, use the remove function
http://www.cplusplus.com/reference/clibrary/cstdio/remove/
Random Solutions  
 
programming4us programming4us