Jump to content
Sign in to follow this  
FredMellink

FileWrite vs. _FileWriteLog while running test on command line

Recommended Posts

FredMellink

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

Share this post


Link to post
Share on other sites
abberration

It works for me. I compiled this script:

#include <File.au3>
$LogFile = $CmdLine[1] & "\test.log"
_FileWriteLog($LogFile, "version20130902" & @CR)

 

Then I ran this from a batch file:

test.exe C:\Users\MyComputer\Desktop\test

Log entry written:

2013-09-02 18:24:55 : version20130902


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites
LarsJ

Share this post


Link to post
Share on other sites
TheSaint

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

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
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
Sign in to follow this  

×