TecGuy Posted September 16, 2009 Share Posted September 16, 2009 (edited) I am running a program that reading the output of a dos program and dumping it to a log file That i have working. What i would like it to do is to also read the output for part of a string to get an error code like this (code10) to terminate and and restart $command = Run(@ComSpec $command = Run(@ComSpec & " /c " & \program.exe","",@SW_HIDE,3) $read = "" Do If StdoutRead($command,1,True) Then $read = StdoutRead($command) If Then ExitLoop _FileWriteLog("C:\" & $fld & "\" & $Bdir1 & "_" & $sta & "_" & @YEAR & @MON & @MDAY & "_"& @HOUR & @MIN &$ext,$read) If Not StringInStr($read,"complete") Then $read = "" EndIf Until $read <> "" StdinWrite($command,"x") Thanks for any help you can give and any suggestions that would make this more effecient i would appreciate it. Thanks, TecGuy Edited September 16, 2009 by TecGuy Link to comment Share on other sites More sharing options...
ctyankeeinok Posted September 16, 2009 Share Posted September 16, 2009 I may be wrong, but it looks like you are doing a true/false test on a command that returns a string - StdOutRead returns a string. Check the Help file on StdOutRead. Link to comment Share on other sites More sharing options...
TecGuy Posted September 16, 2009 Author Share Posted September 16, 2009 Thank you for your help that resolved the issue I do have another issue. I would like to use a word like in the following statement to trigger an error If Not StdoutRead($command) = "error" Then The Problem is that the word is only part of the string Thanks Link to comment Share on other sites More sharing options...
ctyankeeinok Posted September 16, 2009 Share Posted September 16, 2009 Look at StringInStr Link to comment Share on other sites More sharing options...
TecGuy Posted September 16, 2009 Author Share Posted September 16, 2009 (edited) Thanks for your reply. I looked at StringInStr and this is what i am running into Then String I will be using will have a date time stamp at the beginnig of the string and i will not be able to keep that constant is there a way to look at each line for the word "error" without knowing any of the string it will be in? Thanks, Edited September 16, 2009 by TecGuy Link to comment Share on other sites More sharing options...
ctyankeeinok Posted September 17, 2009 Share Posted September 17, 2009 I am not sure I understand your problem. StringInStr will return the position of a substring anywhere in a string. It returns 0 if it is not found. You could do something like the following, but you will probably need to improve this: $read = StdoutRead($command) $errorpos = StringinStr($read, "error") if $errorpos > 0 Then MsgBox(0,"Error found", $read) EndIf Link to comment Share on other sites More sharing options...
TecGuy Posted September 17, 2009 Author Share Posted September 17, 2009 (edited) I apologize for my lack of clarity. I have been trying to get this to work and don't know Autiot well enought to find the answer. I am willing to do the work just don't know where to look. This is what i am trying to do 1. I have a program that runs in dos and i noticed that when i disconnect from the internet it populates the Autiot console but if plugged in it doesn't. i want to trigger an error when the internet is disconnected or does not exist and restart the script until reconnected or reaches 10 retry's then exit. My guess is that the error that is populating the console is from $STDERR_CHILD but when i tried to implement your suggestion nothing happened. I am on day 14 since i found Autiot and just don't know this program well enough to solve. Any help would be greatly appreciated. I apologize if you have already answered my question here is the sample script i am working with: EnvSet("Log_CMD",EnvGet("Log_CMD") & $var & " --log-file=/cygdrive/" & $RsDr & "/" & $dir & "/" & $fld & "/" & $Bdir1 & "_" & $out & "_" & @YEAR & @MON& @MDAY&"_" & @HOUR & @MIN & @SEC & $ext) Local $command = Run(@ComSpec & " /c " & "%home%\Program.exe","",@SW_HIDE,3) While 1 For $i = 1 to 10 $read = "" Do If StdoutRead($command,1,True) Then $read = StdoutRead($command) If @error Then ExitLoop _FileWriteLog("C:\Config.Msi\" & $fld & "\" & $Bdir1 & "_" & $sta & "_" & @YEAR & @MON & @MDAY & "_"& @HOUR &@MIN &$ext,$read) If Not StringInStr($read,"Terminating secure channel ...") Then $read = "" ; EndIf Until $read <> "" StdinWrite($command,"x") Next Edited September 17, 2009 by TecGuy Link to comment Share on other sites More sharing options...
ctyankeeinok Posted September 17, 2009 Share Posted September 17, 2009 I can't solve the specific problem you are tryng to work, but I can tell you that having StdOutRead as the subject of an If statement is not going to work because it returns a string, not true/false. Also, StringInStr returns a value, not true/false. You need to look more closely at the functions, what they return and restructure your code accordingly. Link to comment Share on other sites More sharing options...
TecGuy Posted September 18, 2009 Author Share Posted September 18, 2009 Thanks for your reply. Your are absolutely right. I found the following on the forum that allowed me to see the error code. One thing i was doing was not running runwait which allowed the error codes from the program to be generated I give the following thread http://www.autoitscript.com/forum/index.php?showtopic=297 the credit RunWait("C:\SomeCompiledScript.exe") $Var = @error MsgBox(0,"", $Var) Exit Thanks for all of you help, TecGuy 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