FredMellink Posted September 2, 2013 Share Posted September 2, 2013 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 More sharing options...
abberration Posted September 2, 2013 Share Posted September 2, 2013 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 Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
LarsJ Posted September 2, 2013 Share Posted September 2, 2013 FredMellink, It does work:#include <File.au3> Global $sLogFile = "mylog.log" If $CmdLine[0] = 1 Then $sLogFile = $CmdLine[1] _FileWriteLog($sLogFile, "version20130902" & @CRLF) Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
TheSaint Posted September 3, 2013 Share Posted September 3, 2013 (edited) 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 September 3, 2013 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now