Frage

int main (int argc, char *argv[])
{
    FILE *in;
    extern FILE *popen();
    char buff[512];
    char buff2[1024];

    snprintf(buff2, 1024, "ifconfig eth0 | grep HWaddr | awk '{for(i=0;i<5;i++) sub(":","-",$5); print $5}'");
    if(!(in = popen(buff2, "r")))
    {

            exit(1);
    }

    while(fgets(buff, sizeof(buff), in)!=NULL){
            printf("%s", buff);
    }
    pclose(in);

    return 0;
}

I have no idea why I am getting this error, can some one help me please.

War es hilfreich?

Lösung

Look at your use of open/close double quotes on this line:

    snprintf(buff2, 1024, "ifconfig eth0 | grep HWaddr | awk '{for(i=0;i<5;i++) sub(":","-",$5); print $5}'");

You are closing the double quotes right before the :. Try escaping the double-quotes within the string with \".

Andere Tipps

Try escaping your quotation marks within your string.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top