pghbrea Posted December 10, 2014 Share Posted December 10, 2014 (edited) I've been learning by reading and "I think" doing ok at it. I have this script that's meant to identify the status of two processes running. It always generates results but will not complete. Sometimes I get 60 results, sometimes 150 but there's always at least 100 hosts that exist in the txt file that have no results. You can see I was doing some testing and I eventually plan to look into a GUI to capture the username/password to be used. I've removed any identifying data and made it general. expandcollapse popup#include <GUIConstants.au3> #include <array.au3> #include <FileConstants.au3> #include <File.au3> #include <MsgBoxConstants.au3> Local $data, $data1, $pid, $pid1, $res, $res1 $output_file = @MyDocumentsDir & '\file.csv' $read_file = FileOpen (@MyDocumentsDir & '\ips.txt', 0) FileDelete ($output_file) $write_file = FileOpen ($output_file, 1) $v = _FileCountLines (@MyDocumentsDir & '\ips.txt') $x = 1 FileWrite ($write_file, 'HOST' & ',' & 'AV' & "," & 'LOGS' & @CRLF) Do $res = 0 $res1 = 0 $data = 0 $data1 = 0 ; MsgBox (0, 'Test', $res & ' & ' & $res1) $ip = FileReadLine ($read_file, $x) $pid = RunAs('username', 'domain', 'password', 0, 'sc \\'&$ip&' query "servicename"', '', @SW_HIDE, 2) Do $data &= StdOutRead($pid) Until @error ; MsgBox(0, 'result', $data) $pid1 = RunAs('username', 'domain', 'password', 0, 'sc \\'&$ip&' query "servicename"', '', @SW_HIDE, 2) Do $data1 &= StdoutRead($pid1) Until @error ; MsgBox(0, 'result', $data1) If StringInStr($data, 'running') Then $res = 'running' Elseif StringInStr($data, 'does not exist') Then $res = 'not running' ElseIf StringInStr($data, 'unavailable') Then $res = 'RPC error' EndIf If StringInStr($data1, 'running') Then $res1 = 'running' Elseif StringInStr($data1, 'does not exist') Then $res1 = 'not running' ElseIf StringInStr($data1, 'unavailable') Then $res1 = 'RPC error' EndIf ; MsgBox (0, 'Result', $res & ' & ' & $res1) ; MsgBox (0, 'Resut', 'Not a Windows Server') $x = $x+1 ; MsgBox (0, 'value x', $x) ; MsgBox (0, 'value v', $v) FileWrite ($write_file, $ip & ',' & $res & "," & $res1 & @CRLF) Until $x = $v+1 FileClose ($output_file) FileClose ($write_file) Edited December 10, 2014 by pghbrea Link to comment Share on other sites More sharing options...
MikahS Posted December 10, 2014 Share Posted December 10, 2014 Welcome to the AutoIt forum! Using code tags with greatly help the clarity of your code. By using autoit code tags [ autoit ] ; code goes here [ /autoit ] (remove the spaces) you can have a box like this. Local $variable = "example" ;<<<<example Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
pghbrea Posted December 10, 2014 Author Share Posted December 10, 2014 Bump asking for any ideas? Link to comment Share on other sites More sharing options...
Jfish Posted December 11, 2014 Share Posted December 11, 2014 I would use some de-bugging. You have a lot of nested "do" loops. Are you sure they can all be satisfied? If one is not it will be an infinite loop and make it so your script does not end. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted December 11, 2014 Share Posted December 11, 2014 I would add Opt("TrayIconDebug", 1) and check how things are going while the script runs, maybe even slow down the program with a bunch of sleeps, or MsgBoxes to see where things may go wrong Link to comment Share on other sites More sharing options...
Jfish Posted December 11, 2014 Share Posted December 11, 2014 (edited) I would also write $x and $v to the console to see what numbers you are getting. If $x does not equal $v+1 it will run forever. something like this: consolewrite(@crlf& "***This is $x "& $x &"***" & @crlf) consolewrite(@crlf& "***This is $v "& $v &"***" & @crlf) That will show their values on separate lines every time the do loop runs. I would add it just before the Until $x = $v+1 Edited December 11, 2014 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
pghbrea Posted December 12, 2014 Author Share Posted December 12, 2014 Thanks for the recommendation. I found the problem but am not sure how to resolve it. What seems to be occuring is the runas statement is completing before the stdoutread can get the information it needs so I seem to be stuck in that Do loop Do $data1 &= StdoutRead($pid1) Until @error Link to comment Share on other sites More sharing options...
Developers Jos Posted December 12, 2014 Developers Share Posted December 12, 2014 (edited) It simply means that your shelled program doesn't finish. Try without the @sw_hide and read both STDOUT and STDERR to see if there are any errors shown: $pid1 = RunAs('username', 'domain', 'password', 0, 'sc \\'&$ip&' query "servicename"', '',Default, 8) Jos Edited December 12, 2014 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
pghbrea Posted December 12, 2014 Author Share Posted December 12, 2014 I used @SW_MAXIMIZE after messing around with your recommendation without success. What seems to be happening is the shelled program does finish yet the Do loop does not get the result. Link to comment Share on other sites More sharing options...
TheSaint Posted December 13, 2014 Share Posted December 13, 2014 Another handy way to troubleshoot, is to write values to a txt or ini file at various points throughout your code, this avoids issues of the console or msgbox. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
computergroove Posted December 13, 2014 Share Posted December 13, 2014 I used @SW_MAXIMIZE after messing around with your recommendation without success. What seems to be happening is the shelled program does finish yet the Do loop does not get the result. Add some sleep lines to your code and a msgbox to see if the result of the shell executed exe is reaching your script. This could be autoit or your shelled exe. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Geir1983 Posted December 13, 2014 Share Posted December 13, 2014 Why not add a timeout on the loop if something goes wrong? $Timeout = Timerinit() Do $data1 &= StdoutRead($pid1) Until @error OR (TimerDiff($Timeout) > 1000) 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