0

I am collecting netstat information. the program is working but when in tinyxml for tag it shows null while in console application same program runs successfully

char command[50];

TiXmlElement* msg31 = new TiXmlElement( "Port" );
TiXmlElement childText0( "Type" );
TiXmlNode* childNode0;
CString sTemp;

strcpy( command, "netstat -aon | findstr 3306" );

sTemp.Format(_T("%s"), system(command));
childText0.value = "Mysql_port" ;           
childText0.LinkEndChild(new TiXmlText(GetCharArray(sTemp)));
childNode0 = msg31->InsertEndChild( childText0 );               
childText0.Clear();
net->LinkEndChild(msg31);

this program runs sucessfully. but only problem is in xml it shows null value. output of xml is as below. what is the problem with code?

Output of XML(you can see Mysql_port is null)

            <Network>
            <Port>
                <Mysql_port>(null)</Mysql_port>
            </Port>
        </Network>
Csq
  • 5,775
  • 6
  • 26
  • 39
user3505712
  • 895
  • 1
  • 11
  • 20

1 Answers1

0

The return value of system() is int, more specifically the exit code of the executed program, which supposed to be zero if the program succeeds.

So, yes, that is a null pointer there.

See this question on how to get the output itself.

Community
  • 1
  • 1
Csq
  • 5,775
  • 6
  • 26
  • 39