Jump to content

FileWrite vs. _FileWriteLog while running test on command line


Recommended Posts

Hello Folks

For writing log info to a file, there are two functions I tried: "FileWrite" and "_FileWriteLog"

When I use "_FileWriteLog" and run the script either by using F5 or running the exe by double-clicking the code:

_FileWriteLog($LogFile, "version20130902" & @CR)

results in "2013-09-02 15:50:44 : version201309020" in the log file. This is as expected. However if I run the script on command line, using $Cmdline for indicating the log path, the log file is empty. If I replace all _FileWriteLog commands by FileWrite, I get logging, but without the timestamp. Who knows what is wrong?

Of course there is the workaround using

FileWrite($logFile, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC &

But I just wanne know why _FileWriteLog doesn't work with command-line running of the script.

Thanks for feedback. Regards, Fred

Link to comment
Share on other sites

FredMellink, It does work:

#include <File.au3>

Global $sLogFile = "mylog.log"

If $CmdLine[0] = 1 Then $sLogFile = $CmdLine[1]

_FileWriteLog($sLogFile, "version20130902" & @CRLF)
Link to comment
Share on other sites

At a guess, I can only conclude one of three things.

[1] You don't have #include <File.au3> at the top of your script.

or

[2] Your $sLogFile variable is incorrect in some way.

or

[3] Your $sLogFile doesn't exist, which it needs to for _FileWriteLog.

Obviously, when you use FileWrite, you are also opening and closing your log file using additional commands, and thus probably supplying the correct path to your log file in the process (and creating it at need).

If [3] is the case, you can use _FileCreate($sLogFile) before the _FileWriteLog line.

EDIT

You may need to look at what error might be returned from _FileWriteLog (i.e. use a MsgBox to show result).

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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...