DaveToland Posted May 2, 2006 Share Posted May 2, 2006 (edited) I have created a small batch file that logs the progress of my AutoIT script. It works by taking a passed in parameter and prepending a date and time. I have tried to call this from the script using the Run command like so: Run ("c:\autoit\logger.bat opening vpn connection dialog") 'c:\autoit\logger.bat' is the location and name of the batch file 'opening vpn connection dialog' is the text to be logged. The problem is that as soon as the script encounters the space between 'opening' and 'vpn' it breaks. So the output in the log file reads: 2006/05/02 16:45:17: opening Can anybody think of a way of inserting a space. I have experimented trying ASCII characters, and the like but it just outputs the text (2006/05/02 16:45:17: opening{ASC 32}vpn....). The only way I have thought of getting around this is to insert underscores (_) or dots (.) in place of the spaces but this doesn't read very well. Any help would be appreciated. many thanks Edited May 2, 2006 by DaveToland Link to comment Share on other sites More sharing options...
cdkid Posted May 2, 2006 Share Posted May 2, 2006 Run('c:\autoit\logger.bat "opening vpn dialog"') ~cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide! Link to comment Share on other sites More sharing options...
DaveToland Posted May 3, 2006 Author Share Posted May 3, 2006 Run('c:\autoit\logger.bat "opening vpn dialog"') ~cdkid Cheers mate, that works nicely. Although now I have tried to be a bit more generic by putting the log syntax within a function call. This results in the same sort of problem: Func LogMe($comment) run ('c:\autoit\Logger.bat $comment') EndFunc results in : 2006/05/03 11:49:48: $comment 2006/05/03 11:49:48: $comment 2006/05/03 11:49:48: $comment 2006/05/03 11:49:48: $comment 2006/05/03 11:49:48: $comment 2006/05/03 11:49:48: $comment Am I not going to be able to use this way? I have tried a few ideas to get around it and I cannot see a solution. Thanks for your help Dave Link to comment Share on other sites More sharing options...
JerryD Posted May 3, 2006 Share Posted May 3, 2006 Cheers mate, that works nicely. Although now I have tried to be a bit more generic by putting the log syntax within a function call. This results in the same sort of problem: Func LogMe($comment) run ('c:\autoit\Logger.bat $comment') EndFunc You want: Func LogMe($comment) run ('c:\autoit\Logger.bat ' & $comment) EndFunc Note the trailing space after .bat. Also, in your first entry, you may want to use something like: $BatFile = FileGetShortName ( @ProgramFilesDir & '\AutoIt\logger.bat' Run ( $BatFile & ' "opening vpn connection dialog"' ) The reason being that you get past the problem of spaces in the batch file's path or name. Link to comment Share on other sites More sharing options...
DaveToland Posted May 3, 2006 Author Share Posted May 3, 2006 (edited) Thanks again The reason being that you get past the problem of spaces in the batch file's path or name. ..this is not an issue, but thanks for the tip. Although, i'm now experiencing the problems with it only recording the first word out of each log comment: ;;device name or number $device_to_call = "qspeeqgw000" LogMe ("Device to call: " & $device_to_call) ;;duration in milliseconds $duration_of_call = 8000 LogMe ("Duration of call: " & $duration_of_call) ;;start infintate 13 minute loop LogMe ("Beginning 13 minute loop") While 1 send ("#d") LogMe ("Minimising to desktop") .... //// Func LogMe($comment) run ('c:\autoit\Logger.bat ' & $comment) EndFunc results in: 2006/05/03 13:09:49: Device 2006/05/03 13:09:49: Opening 2006/05/03 13:09:49: Duration 2006/05/03 13:09:49: Beginning 2006/05/03 13:09:49: Minimising I would have thought putting the "double quotes" within the function call would have got me around this..? Edited May 3, 2006 by DaveToland Link to comment Share on other sites More sharing options...
MHz Posted May 3, 2006 Share Posted May 3, 2006 I would have thought putting the "double quotes" within the function call would have got me around this..?Protect the spaces in the parameters that are sent to the bat with quotes. Quotes around the bat could be wise if you were to possibly have spaces to safe guard with files or folders with the same first word in the filename. This does both bat and parameter: Func LogMe($comment) Local $file = 'c:\autoit\Logger.bat' If FileExists($file) Then Run('"' & $file & '" "' & $comment & '"') Return 1 Else Return 0 EndIf EndFunc Link to comment Share on other sites More sharing options...
DaveToland Posted May 3, 2006 Author Share Posted May 3, 2006 (edited) Protect the spaces in the parameters that are sent to the bat with quotes. Quotes around the bat could be wise if you were to possibly have spaces to safe guard with files or folders with the same first word in the filename. This does both bat and parameter: Func LogMe($comment) Local $file = 'c:\autoit\Logger.bat' If FileExists($file) Then Run('"' & $file & '" "' & $comment & '"') Return 1 Else Return 0 EndIf EndFunc that works superbly , but.... this is REALLY weird. Look at the order the log statements appear in the code, and then look at the order they appear in the log file. They're out of sync LogMe ("Starting Ingenious Client Automation Script (D.Toland) - v1.0") ;;device name or number $device_to_call = "qspeeqgw000" LogMe ("Device to call: " & $device_to_call) ;;duration in milliseconds $duration_of_call = 8000 LogMe ("Duration of call: " & $duration_of_call) ;;start infintate 13 minute loop LogMe ("Beginning 13 minute loop") While 1 send ("#d") LogMe ("Minimising to desktop") run ("C:\Program Files\Cisco Systems\VPN Client\ipsecdialer.exe") LogMe ("Opening VPN Dialer") //// 2006/05/03 13:23:19: Beginning 2006/05/03 13:23:19: Duration 2006/05/03 13:23:19: Starting 2006/05/03 13:23:19: Device 2006/05/03 13:23:19: Opening 2006/05/03 13:23:19: Minimising Edited May 3, 2006 by DaveToland Link to comment Share on other sites More sharing options...
MHz Posted May 3, 2006 Share Posted May 3, 2006 (edited) Use RunWait instead of Run in the function, and see if that helps with correct timings. Edit: Like this Func LogMe($comment) Local $file = 'c:\autoit\Logger.bat' If FileExists($file) Then RunWait('"' & $file & '" "' & $comment & '"') Return 1 Else Return 0 EndIf EndFunc Edited May 3, 2006 by MHz Link to comment Share on other sites More sharing options...
DaveToland Posted May 3, 2006 Author Share Posted May 3, 2006 Use RunWait instead of Run in the function, and see if that helps with correct timings. Edit: Like this Func LogMe($comment) Local $file = 'c:\autoit\Logger.bat' If FileExists($file) Then RunWait('"' & $file & '" "' & $comment & '"') Return 1 Else Return 0 EndIf EndFunc PHEW!!! Finally got it working. Used RunWait with a combination of Sleep statements and removed a few of the log statements which took focus away from the windows in a couple of critical places. My boss is now happy and I can close this project, at last... Thank you guys very much for your help with this, I cannot thank you enough, you've been amazingly helpfull. A big thumbs up to you all. Regards Dave 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