My code's IF-THEN does not work for 2nd iteration. This is due to, the jar processing take some time to write it result inside the output.txt.
Since the writing is a bit late, my code's 2nd iteration will always read the previous written value inside the output.txt in order to pass it to the IF-THEN.
For example, in 1st iteration: output.txt --> 0.9888 twrite.txt --> msg: ok
2nd iteration:
output.txt --> 0.5555
twrite.txt --> msg: ok
//the IF-THEN still gives this result which is based on previous iteration. it should be msg: not ok . since it is < 0.7
I need help, how to solve this 'delay' problem?
HRESULT CButtonDemoBHO::onDocumentComplete(IDispatch *pDisp, VARIANT *vUrl){
ATLTRACE("CButtonDemoBHO::onDocumentComplete %S\n", vUrl->bstrVal);
WinHttpClient client(vUrl->bstrVal);
client.SendHttpRequest();
wstring httpResponseHeader = client.GetHttpResponseHeader();
wstring httpResponse = client.GetHttpResponse();
writeToLog(httpResponse.c_str());
if (isMainFrame(pDisp)){
m_normalPageLoad=false;
FILE *child = _popen("javaw -jar c:\\simmetrics.jar c:\\chtml.txt c:\\thtml.txt > c:\\output.txt", "r");
fclose(child);
char readnumber[10];
float f = 0;
FILE *file11 = fopen("c:\\output.txt","r");
char* p = fgets(readnumber,10,file11);
std::istringstream iss(p);
iss >> f;
if (f > 0.7)
{
wfstream file12 ("c:\\twrite.txt", ios_base::out);
file12 << "Msg: ok";
file12.close();
}
else
{
wfstream file12 ("c:\\twrite.txt", ios_base::out);
file12 << "Msg: not ok";
file12.close();
}
iss.clear();
fclose(file11);
return S_OK;
}
return S_OK;
}