samueltb Posted August 6, 2007 Share Posted August 6, 2007 Hi I'm currently attempting to write a script which checks the time on a server, if the time is prior to 7:45 I want to force the script to exit and set errorlevel which I'll be able to pick up externally of the script using altiris. the script at present will create a file which I can then do a dir command and if exist continue, it would be easier and cleaner if I could sipmly set the error level and pick that up, hope this makes sense. #include <Date.au3> FileDelete ("c:\temp\time.txt") $var1 = _NowTime () if $var1 < "07:45:00" Then FileOpen ("c:\temp\time.txt", 1) FileWrite ("c:\temp\time.txt", $var1) FileClose ("c:\temp\time.txt") endif Thanks for any help Link to comment Share on other sites More sharing options...
jvanegmond Posted August 6, 2007 Share Posted August 6, 2007 (edited) You are using the File functions wrong.$File = FileOpen("C:\temp\time.txt", 2) FileWrite($File,$var1) FileClose($File)Edit: Try to see if you can capture the 'Exit' value from the program. Then use Exit 1 and Exit 0 to give the difference. Edited August 6, 2007 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
samueltb Posted August 6, 2007 Author Share Posted August 6, 2007 Cheers for the help, but I'm none the wiser, the exit value is always 0 as the script always executes. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 6, 2007 Share Posted August 6, 2007 You could start by reading the help file. You might check out the Exit command in the help file. This might help (it's from the help file): Exit -------------------------------------------------------------------------------- Terminates the script. Exit [return code] Parameters return code [optional] Integer that sets the script's return code. This code can be used by Windows or the DOS variable %ERRORLEVEL%. The default is 0. Scripts normally set an errorlevel of 0 if the script executed properly; error levels 1 and above typically indicate that the script did not execute properly. It would probably help to spend more time with the help file, too. Do we see a pattern here? 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...
samueltb Posted August 6, 2007 Author Share Posted August 6, 2007 I have tried the help file, I modified my script to display the exit code but in dos %errorlevel% is reporting back as 0 regardless of what EXIT is set to. #include <Date.au3> Opt("OnExitFunc", "endscript") Func endscript() MsgBox(0,"","after last statement " & @EXITCODE) EndFunc FileDelete ("c:\temp\time.txt") DirCreate ("c:\temp") $var1 = _NowTime () if $var1 < "07:00:00" Then $file = FileOpen ("c:\temp\time.txt", 1) FileWrite ("c:\temp\time.txt", $var1) FileClose ("c:\temp\time.txt") Exit (1) EndIf exit (0) Link to comment Share on other sites More sharing options...
MHz Posted August 6, 2007 Share Posted August 6, 2007 Using < or > with strings may not give you the results you want. This may work before 7am with some luck #include <Date.au3> Opt("OnExitFunc", "endscript") Func endscript() MsgBox(0, "", "after last statement " & @exitCode) EndFunc FileDelete("c:\temp\time.txt") DirCreate("c:\temp") $var1 = _NowTime(4) If Int(StringLeft($var1, 2)) < 7 Then $handle = FileOpen("c:\temp\time.txt", 1) If $handle <> -1 Then FileWrite($handle, $var1) FileClose($handle) EndIf Exit 1 EndIf Exit Use the file handles also. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 6, 2007 Share Posted August 6, 2007 (edited) Maybe simpler: #include <File.au3> FileDelete("c:\temp\time.txt") If (@HOUR < 7) Or (@HOUR = 7 And @MIN < 45) Then _FileWriteLog("c:\temp\time.txt", "Tried to start script before 07:45.") Exit 1 Else Exit 0 EndIf Note, _FileWriteLog() adds a date/time stamp automatically, which for me is cleaner and easier. Edited August 6, 2007 by PsaltyDS 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...
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