#171883 - 2006-12-21 06:47 PM
Re: @error handling? and redirection to a text file (append)
[Re: itdaddy]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
My thoughts...
; initialize array of computer names
$FourthAveArray = "ftran1", "ftran2", "ftran3", "SPARE", "FACCTG8", "FACCTG1", "FACCTG2"
; enumerate the array
For Each $Element In $FourthAveArray
; Get the current millisecond count - not good as this is the MSec portion of the current minute
; $Time = @msec
; Get the current millisecond count - not good as this is the MSec portion of the current minute
$Time = @TICKS
; copy the source to dest - quotes were missing
; copy c:\fspcopy\*.mdb "\\"+$Element+"\c$\fsp\mdb" /c /r
; with quotes, and spaces to improve readability - will still fail because "\c$\..." is
; interpreted as a variable "$", which isn't defined. The strings is interpreted as
; "\c\fsp...", which is not valid
; copy "c:\fspcopy\*.mdb" "\\" + $Element + "\c$\fsp\mdb" /c /r
; corrected copy string - better would be to use Chr(36), or SetOption("NoVarsInStrings", "On")
copy "c:\fspcopy\*.mdb" "\\" + $Element + "\c$$\fsp\mdb" /c /r
IF @ERROR <> 0
; best practice - enclose string in quotes - "append" is the default - not needed
; also - capture the return codes, and close the redirection
; REDIRECTOUTPUT (failure.txt, 0)
$RC=RedirectOutput('failure.txt')
; "?" is not a print statement - it's a CR/LF.. should come AFTER the message
; ? $Element
$Element ' - ' @SERROR ?
$RC=RedirectOutput('')
Endif
; get elapsed time for this process - corrected to use TICKS
$Time = @TICKS - $Time
Next
Glenn
Edited by Glenn Barnas (2006-12-21 07:44 PM)
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#171895 - 2006-12-21 10:46 PM
Re: @error handling? and redirection to a text file (append)
[Re: Les]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
I never think quotes are optional (except - MAYBE - while golfing, but even that gives me the willies), but Doc just mentioned that unquoted strings usually work - that's all. Quoting the string is absolutely correct, and in my opinion, necessary.
For ITDaddy's benefit -
The "$" is the variable indicator in Kix - everything that follows it, letters, numbers, and some characters - forms a variable name. The "$" by itself is a legal variable name, often used as a "throw-away" var to catch return codes that aren't needed.
The process of converting variable names to their contents is called "variable expansion", and it - by default - occurs inside of strings. Most of us have decided that this is NOT a good thing, specifically for what you are experiencing here. You actually WANT a "$" inside the string, and not the content of a variable.
One way to do it is to "escape" the "$" by doubling it - Kix ignores variable expansion when it sees "$$" and simply puts a single "$" in its place. OK for "quick-n-dirty" scripts, but not for scripts that will see long-term use, or more advanced scripts.
A second form is the use of Chr(36), which is the "$" char. This always works, but is less obvious when debugging, or reading someone else's code.
What's preferred, and what you'll see in most of our scripts, is the command $RC = SetOption('NoVarsInStrings', 'On') This tells Kix to ingore the "$" inside of quoted strings (another reason ALL strings should be quoted). This is placed at the beginning of the script. Doing this will prevent any confusion of the "\\server\c$\folder" form of UNC paths.
There are other SetOption values that most of us use, and they force better programming habits by making you declare your vars before use and things like that. Get familiar with the basics of Kix first, then try turning on "Explicit" and see if you declared all your vars..
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#171896 - 2006-12-22 12:02 AM
Re: @error handling? and redirection to a text file (append)
[Re: Glenn Barnas]
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Glenn, AFAIK, C$ is interpreted as C$, and not as a variable, even when the option "NoVarsInStrings" is "Off". The difference is the $ at the end.
Break On
Dim $RC
$RC = Dir("\\"+@WKSTA+"\C$\*")
While $RC <> "" AND @ERROR = 0
? $RC
$RC = Dir()
Loop
But I also prefer to set "NoVarsInStrings" to "On".
|
Top
|
|
|
|
#171919 - 2006-12-22 01:53 PM
Re: @error handling? and redirection to a text file (append)
[Re: Witto]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Hmm - you are right.. although I seem to recall this being a problem in earlier versions (maybe 10+ years ago in the 16b version?)
Or maybe I'm just thinking of other languages where it is a problem. Still, it's best not to use Var_ID chars in strings. It won't be a problem in this specific example, but consider something like
which produces C4 - a potentially explosive result. Just because a letter preceeds the "$" doesn't mean it won't get interpreted.
I have a picture hanging in my office - a guy using his laptop at a funeral. The caption says "just because you CAN doesn't mean you SHOULD!" Outside of KixGolf, it's a good rule for programming.
ITDaddy: I may come across like a teacher because it's hard to shake 15+ years teaching IT subjects, including Unix and MCSE. As for rocketry, it's a blast, but no where near that expensive. The average rocket costs about $200 to build (parts/paint/epoxy), and flies with a $100 flight computer (records altitude and speed, fires 2 ejection charges for parachute deployment), and my larger rockets sometimes use a $600 avionics package that transmits real-time flight telemetry, including speed, altitude, and GPS location. The motors cost between $30 and $150. All of these costs are one-time purchases of reusable items. Fuel for the motors can run between $2 and $200 per flight for the rockets that I fly, although there are larger rockets that are much more expensive to build and fly. I build in the winter and fly in the summer, rarely spend more than an average of $200/month on the hobby.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#171946 - 2006-12-22 11:55 PM
Re: @error handling? and redirection to a text file (append)
[Re: NTDOC]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Net Stop will stop the task scheduler service, and affect all scheduled tasks. If you want to control individual task events, or even specific triggers of a selected task, the tcLib library will get the job done. It's posted here on KORG, but the latest version is available from my web site. It's too big to be easily maintained here.
tcLib consists of a KiX library of functions, and Microsoft's JT.exe. Once you place JT.exe into a folder in your PATH (like the Windows folder), just include the tcLib in your script and disabling (suspending) a task is as easy as:
tcInit()
tcDefineTask('taskname', 'SUS=1')
$RC = tcSetEvent('hostname', ' taskname')
One of the cool things about tcLib (and the task scheduler) is that you can define a task event without a trigger (time to run), and then use tcExecute('host', 'eventname') to run it with the defined credentials anytime you need to. This is how I implement a network-wide power shutdown process. Each system has a shutdown command, and a single system monitors the UPS array and invokes the scheduled task on the other systems to shut them down.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 628 anonymous users online.
|
|
|