开发者

Cannot work for 2nd iteration because of writing delay

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

 开发者_JAVA技巧  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;
}


Do you really need to write the output of the JAR to results.txt? You can use _popen to directly pipe the stream directly instead of writing to the file and reading it into a variable.

Check out the MSDN documentation on _popen, they have an example on this.

Also, this would solve your problem of the "writing delay" since you're directly reading the information from the javaw application instead of reading it from output.txt.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜