Member_2_4225740
asked on
How do I append DOS output to a file from an AutoIt script?
I've created an AutoIt script that gives me quick access to commonly used programs I use to perform routine maintenance on the computers at the office where I work.
One function I use is the NET TIME command so I can verify that the computer is set to receive the time from our server. I am trying to record the output of this command to a log file for future reference but my script is not logging it.
I have these variables initialized at the beginning of my script:
$path="\\lrecdops-dc3\d$\h ome_folder s\michael\ maintenanc e\"
$file=$path & @ComputerName & ".txt"
And here is the code from the segment that runs the NET TIME command:
RunWait("net time >> " & $file)
FileOpen ($file, 1 )
FileWriteLine($file, _Now() & " - Ran NET TIME check" & @LF)
FileClose ($file)
When I run the script, the DOS window flashes, but when I check the log all I see is the line saying it ran the NET TIME check.
How do I get the script to append the NET TIME output to the log file?
One function I use is the NET TIME command so I can verify that the computer is set to receive the time from our server. I am trying to record the output of this command to a log file for future reference but my script is not logging it.
I have these variables initialized at the beginning of my script:
$path="\\lrecdops-dc3\d$\h
$file=$path & @ComputerName & ".txt"
And here is the code from the segment that runs the NET TIME command:
RunWait("net time >> " & $file)
FileOpen ($file, 1 )
FileWriteLine($file, _Now() & " - Ran NET TIME check" & @LF)
FileClose ($file)
When I run the script, the DOS window flashes, but when I check the log all I see is the line saying it ran the NET TIME check.
How do I get the script to append the NET TIME output to the log file?
Futhermore, it would seem that the net time application writes it's output to a different stream; try this instead:
RunWait("net time 2> " & $file)
RunWait("net time 2> " & $file)
ASKER
Well, this is getting quite interesting.
When I run my script and invoke the NET TIME command first, it works fine.
RunWait(@ComSpec & " /k " & "net time >>" & $file)
BUT...
When I have the script write anything to the log file and then try invoking the NET TIME command, I get this error:
The process cannot access the file because it is being used by another process.
That's what was in the DOS window when it flashed. Normally NET TIME takes a few seconds to run.
I think the script is somehow keeping the log file open so NET TIME can't write anything to it.
I'm taking this to the forums on AutoIt's web site and will come back here when I find something out.
When I run my script and invoke the NET TIME command first, it works fine.
RunWait(@ComSpec & " /k " & "net time >>" & $file)
BUT...
When I have the script write anything to the log file and then try invoking the NET TIME command, I get this error:
The process cannot access the file because it is being used by another process.
That's what was in the DOS window when it flashed. Normally NET TIME takes a few seconds to run.
I think the script is somehow keeping the log file open so NET TIME can't write anything to it.
I'm taking this to the forums on AutoIt's web site and will come back here when I find something out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Excellent, thanks for letting us know the solution.
I'll have this thread PAQ'd, and your points refunded.
I'll have this thread PAQ'd, and your points refunded.
ASKER
To answer your question about inserting quotes in a string, I use the CHR function to load its corresponding ASCII code, which is 43.
So if I wanted to use quotes in this string:
net time >> \"" & $file & "\"
I would use
net time >> \" & chr(34) & " & $file & " & chr(34) & "\
So if I wanted to use quotes in this string:
net time >> \"" & $file & "\"
I would use
net time >> \" & chr(34) & " & $file & " & chr(34) & "\
Nice one, thank you.
Closed, 250 points refunded.
modus_operandi
EE Moderator
modus_operandi
EE Moderator
I'm not familiar with the AutoIT language, so you'll have to help me a bit here:
How do you include quotation marks inside a string?
In most other languages, you prepend a backslash, like so:
RunWait("net time >> \"" & $file & "\"")
But based solely on the code you've presented above, it would seem unlikely that this is the correct syntax in AutoIT..