Reading a textfile in windows Vs linux

Hello everyone

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 :)

The while code is below

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
34
35
36
37
38
39
40
41
42
43
44
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 = new char [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.

Thanks in advance for any help you can give.

/Regards Berth

----EDIT------

Changed the while(! to
 
while(infil >> queueName >> queueManagerName >> maxQueueLength >> queueLimit)

and this time it seems to work in both windows/linux/aix so guess it was an easy fix :)
Last edited on
Topic archived. No new replies allowed.