Jump to content

How to read log file created/written in same instance?


Recommended Posts

Hey I searched for something and didn't see any related posts!

One of my programs creates a log file. I have a need to read from that log file after it is written... this situation basically is me taking 2 .exe and making 1 .exe with some fluff taken out. This basic process seems to be an issue. I am able to write to the file, but FileExists will return 1. Something like this:

If $match = "value" Then
 _FileWriteLog ("c:\folder\data.xml","<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>")
        _FileWriteToLine ("c:\folder\data.xml", 1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>", 1)
        _FileWriteToLine ("c:\folder\data.xml", 2, "<Key>", 1)
        _FileWriteToLine ("c:\folder\data.xml", 3, "<Value1>" & $match[1] & "</Value1>", 1)
        _FileWriteToLine ("c:\folder\data.xml", 4, "</Key>", 1)
EndIf
If FileExists ( "c:\folder\data.xml" ) Then
        ; do the thing
       Else
    MsgBox ( 4096 , "Error" , "data.xml file not present." )
EndIf

Is this because the .exe is looking for the file before it is created or before it is saved? Is it simply that I can put in a sleep of some time which will make it so FileExists will work or is there some other method I can use?

Let's pretend I am not using an XML file here and get away from here with your "why are you making XML files like that" posts! :P

Let's pretend it is just a regular old log file. The gist is, I read some data from someplace, make an XML file. Then I must do step 2 which is run an external program that uses that XML file. So then I must make sure the file exists! I can see it in the folder, but get the MsgBox saying it isn't there.

Link to comment
Share on other sites

I would just use straight use an xml dom object...

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.Load($File)

.selectnode

.createelement

.appendchild

.save

just to mention a few...give those a google.

Edit...haha, just read the full post

once you do the save, the file is there, then run the exe.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Yes, this isn't about it being an XML file. I create other "text" files that aren't XML but this is the first time I am trying to read from or verify the existance of the file after creating it. Files created by processes executed by the .exe are seen fine. It is just files that the .exe creates, is not seen by the .exe until after it is closed and re-opened.

To re-iterate, the issue is if I make a file with _FileWriteLog, FileExists() will return 1 (not found) when checking against it and shows me the MsgBox.

Link to comment
Share on other sites

Why do you check $match for a string value, and then attempt to use it as an object that has elements?  This works for me

acted too quickly, this seems to be working fine

#include<file.au3>

$match = "value"


If $match = "value" Then
_FileWriteLog ("c:\folder\data.xml","<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>")
_FileWriteToLine ("c:\folder\data.xml", 1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>", 1)
_FileWriteToLine ("c:\folder\data.xml", 2, "<Key>", 1)
_FileWriteToLine ("c:\folder\data.xml", 3, "<Value1>" & $match & "</Value1>", 1)
_FileWriteToLine ("c:\folder\data.xml", 4, "</Key>", 1)
EndIf

If FileExists ( "c:\folder\data.xml" ) Then
msgbox(0, '' , "do the thing")
Else
MsgBox ( 4096 , "Error" , "data.xml file not present." )
EndIf

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

4 hours ago, iamtheky said:

Why do you check $match for a string value, and then attempt to use it as an object that has elements?

It was a quick redaction of existing code. Actual code reads xml from a website, if a value is present, then it will create the file.

And as my usual method, I believe I have solved this without having to need any of this at all. But at least this topic adds both a problem, and a solution and fills in the missing keyword search results for someone else to find someday.

I was trying to save some time, but the solution (as if a lightbulb like this: :idea: ) put me into an entirely different direction and took the time to do it properly.

Edited by Tripredacus
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...