criticalmass Posted July 21, 2011 Share Posted July 21, 2011 I want to make a function for my program i made. its a diagnostic tool that does pretty neat stuff. but i wanna beable to make a output fucntion that records everything to a text doc. So if they run "Apache Restart" or "Task Manager" I want it to show in the log Apache Restart "Date" "Month" "Year" "Time" Task Manager "Date" "Month" "Year" "Time" how would i go about doing something like this? Link to comment Share on other sites More sharing options...
MrMitchell Posted July 21, 2011 Share Posted July 21, 2011 (edited) FileWriteLine() ?Edit/add: Or search Example Scripts forum for stuff like this... Edited July 21, 2011 by MrMitchell Link to comment Share on other sites More sharing options...
tlman12 Posted July 21, 2011 Share Posted July 21, 2011 FileWriteLine() ? #include<Date.au3> FileWriteLine("Path to logfile",'Apache Restart "' & _Now() & '"') Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 21, 2011 Share Posted July 21, 2011 I use _FileWriteLog() extensively, because it uses a standard format to date/time tag every entry. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
criticalmass Posted July 26, 2011 Author Share Posted July 26, 2011 (edited) I dont understand how this should work. I am sorry I am still learning Here is a example of what I need ; Restart Apache $rsapache = GUICtrlCreateMenuItem("Restart Apache", $hBtnArrowContext) and the file that executes the Restart Apache is. Case $rsapache RunCommandLine("net stop Apache2.2") RunCommandLine("net start Apache2.2") I need to have that go to a log file. I also have: Restart SQL Restart Services and a few others but I need it to go into just a log doesnt have to be the same log but it can be *.log If anyone can help this would be amazing. I need it to be logged every time someone clicks on a button. Edited July 26, 2011 by criticalmass Link to comment Share on other sites More sharing options...
enaiman Posted July 26, 2011 Share Posted July 26, 2011 PsaltyDS gave you a good suggestion - if you would have searched the help file you would have found this: _FileWriteLog -------------------------------------------------------------------------------- Writes current date,time and the specified text to a log file. #Include <File.au3> _FileWriteLog($sLogPath, $sLogMsg [, $iFlag = -1]) Parameters $sLogPath Path and filename of the file to be written to $sLogMsg Message to be written to the log file $iFlag [optional] Flag that defines if $sLogMsg will be written to the end of file, or to the begining. If $iFlag = -1 (default) $sLogMsg will be written to the end of file. If $iFlag <> -1 $sLogMsg will be written to begining of file. Return Value Success: 1 Failure: 0 and set @error @Error: 1 = Error opening specified file 2 = File could not be written to Remarks None Example #include <file.au3> ; _FileWriteLog(@ScriptDir & "\my.log","Text 1") ; _FileWriteLog(@ScriptDir & "\my.log","Text 2") That's what you need to use; you can write to any file once you specify the correct path. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
criticalmass Posted July 27, 2011 Author Share Posted July 27, 2011 sorry didnt understand. for whatever reason my help file is different under windows xp and then under windows 7. Link to comment Share on other sites More sharing options...
criticalmass Posted July 27, 2011 Author Share Posted July 27, 2011 so confused but i will figure it out. Link to comment Share on other sites More sharing options...
enaiman Posted July 27, 2011 Share Posted July 27, 2011 Wow - did you try to think a little about this? Have you tried to put together some code? This is as simple as this: #include <file.au3> ;since it is not specified if _FileWriteLog will create a new file - be sure to create the log files first Global $myLog_1 = @ScriptDir&"\Apache.log" Global $myLog_2 = @ScriptDir&"\Other.log" Case $rsapache RunCommandLine("net stop Apache2.2") _FileWriteLog($myLog_1,"Stopping Apache") RunCommandLine("net start Apache2.2") _FileWriteLog($myLog_1,"Starting Apache") RunCommandLine("run other crap") _FileWriteLog($myLog_2,"Some other crap logged here") ... DOH ... so simple ... Stop being lazy. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 27, 2011 Share Posted July 27, 2011 If the Apache2.2 service quotes the date/time with its own output to the console, then all you have to do is capture that. This can be done by redirection ">>" on the shell command line: $sLogFile = 'C:\Temp\MyLogFile.log' ; ... Case $rsapache RunCommandLine('net stop Apache2.2 >> "' & $sLogFile & '"') RunCommandLine('net start Apache2.2 >> "' & $sLogFile & '"') Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
criticalmass Posted July 28, 2011 Author Share Posted July 28, 2011 I ment to reply to this last night I figured it out. I did it just like enaiman did. Link to comment Share on other sites More sharing options...
enaiman Posted July 28, 2011 Share Posted July 28, 2011 See how good is the old saying "sleep on it"? SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) 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