Having bit of a problem with a rather simple read of a text file, well sort of it works when i compile it in Embarcadero Radstudio 2010 but fails when i use gcc in linux/aix, the program uses a system call to run an mq command to get the current depth on a certain mq channel and if the value is higher then the limit set in the file it should write an alert into a log file, the text file contains 4 variables per line and in windows it read the lines availible but does not seem to have a problem with the eof, in unix it seems to read 1 line to many, tried changing it but ended up with it reading one line to little :)
while(!infil.eof())
{
infil >> queueName >> queueManagerName >> maxQueueLength >> queueLimit;
// cout << "Queue name: " << queueName << endl;
// cout << "Queue manager: " << queueManagerName << endl;
// cout << "Max queue lenght: " << maxQueueLength << endl;
// cout << "Queue limit: " << queueLimit << endl << endl;
string cmdToRunComplete = cmdToRunPart1 + queueName + cmdToRunPart2 + queueManagerName + cmdToRunPart3;
cstr = newchar [cmdToRunComplete.size() +1];
strcpy (cstr, cmdToRunComplete.c_str());
system(cstr);
resultfile.open(testResultFile, ios::in);
if(!resultfile.good())
{
// Tested ok i get this error in the log file.
outapplog << appDate << " " << appTime << " Failed to open the result file 'MQCheck.result' for reading" << endl;
exit(2);
}
resultfile >> currentQueueDepth;
resultfile.clear();
resultfile.close(); // Close the result file so i is not open for the next run
if(currentQueueDepth > queueLimit)
{
outfil.open(errorLogFile, ios::out | ios::ate | ios::app);
if(!outfil.good())
{
outapplog << appDate << " " << appTime << " An error occured when opening the error log" << endl;
exit(2);
}
// Here i need to build the error message to put into the error log
outfil << appDate << " " << appTime << " The queue " << queueName << " has passed the threshold value of: " << queueLimit << " Current queue depth: " << currentQueueDepth << endl;
outfil.close();
}
// currentQueueDepth = 0;
delete[] cstr;
}
It is rather obvious that it reads to much if you uncoment the cout's at the top, maybe it is just a matter of the compiler version, radstudio 2010 is rather new,the gcc version i use is 4.4.4 in fedora 13.