I'm wrote some code which uses socketcan (to make a candump). With this code I initialize socketcan. After it is initialized I create a candump in the terminal. Those values I read into a variable. Now I would like to compare this variable with a string.
The string has a certain format. When I manually run a candump I get the following format:
can0 71A [1] 7F
(2x space) can0 (2x space) 71A (3x space) [1] (2x space) 7F.
I'm able to read the terminal output into the variable (result)
string result = //the string is loaded
** Now I wish to execute some code when the text in the variable "result" is not equal to the following string:
"  can0  71A   [1]  7F" 
The following chunk of code is to make the comparison.
if(result!="  can0  71A   [1]  7F"){
cout<<"input changes";
}
When I execute this code and I send it on the bus the following string. Which is the same as above:
"  can0  71A   [1]  7F" 
the code prints:
"input changes"
(Normally it shouldn't print anything)
When I send the following string on the bus:
"  can0  19B   [1]  6A" 
It also prints: "input changes"
(which is good)
I tried to change the spaces to tabs as well without any result.
Any idea what the problem could be and how to solve this?
* Edit 1 * The following is my code to read the value into the variable "result". (If you see other stupid things in my code, pleas feel free to give some constructive criticisme! I want to learn from my projects.)
    std::string GetCmdOutput(const char * cmd)
{
        char buffer[128];
        string result;
        string different;
        FILE* pipe = popen(cmd,"r");
        int counter=0;
        if(!pipe) throw runtime_error("popen() failed!");
        try {
                if(fgets(buffer,128,pipe) !=NULL){
                        while(counter<2){
                                result +=buffer;
                                cout<<result + "\n";
                                if(result!="  can0  71A   [1]  7F" || result != "  can0  71A   [1]  04" )
                                {
                                        cout<<"changed!\n";
                                        different = result;
                                }
                        }
        }catch(...){
                pclose(pipe);
                throw;
        }
        pclose(pipe);
        pauseCan();
        return different;
}
Kind regards, TM
