phew Posted October 2, 2007 Posted October 2, 2007 hi, i got a console program written in c++, telling me something about the hardware of the computer. to automate it i wrote a little autoitscript that just executes this c++ program (getstat.exe). but now i want it to "interact" with this: so when the "getstat.exe" is executed it returns some strings and then "YES" or "NO" in the last line of the cmd.exe-window, so if it returns "YES" i want my autoitscript to write "getstat.log" with all of the cmd.exe-windows content, if it returns "NO" i want it to do nothing. the problem is, how to read the returned text from the "cmd.exe-window"?
JBeef Posted October 2, 2007 Posted October 2, 2007 mostly of help file - ; Demonstrates StdoutRead() #include <Constants.au3> $foo = Run("getstat.exe", "", @SW_HIDE,$STDOUT_CHILD) $line = "" While 1 $line &= StdoutRead($foo) If @error Then ExitLoop Wend MsgBox(0, "STDOUT read:", $line) - crazy - ~Jap
phew Posted October 2, 2007 Author Posted October 2, 2007 but how do i read out exactly one line and write it to the getstat.log? the getstat.exe returns: line1 line2 ... enabled: YES ... lineN now i want to read out the whole line "enabled: YES" if it matches "YES", "enabled: NO" if it matches "NO" etc., i tried with StringInStr() but actually i did not get it working. help again, please (the line number is always the same, 16!)
phew Posted October 2, 2007 Author Posted October 2, 2007 thanks for your help anyways i'm sure someone else will answer this, that is the forum for - to learn from each other
phew Posted October 2, 2007 Author Posted October 2, 2007 k got it, StringTrimLeft() and StringTrimRight() / StringTrimMid :-)
Moderators SmOke_N Posted October 2, 2007 Moderators Posted October 2, 2007 $iPID = Run("getstat.exe", "", @SW_HIDE, 2) Local $aArray, $sLine While 1 $sLine &= StdoutRead($iPID) If @error Then ExitLoop $aArray = StringRegExp($sLine, "(?s)(?i)(Enabled: \w+)", 1) If IsArray($aArray) Then ExitLoop Wend If IsArray($aArray) Then MsgBox(0, "Found", $aArray[0]) Else MsgBox(16, "Error", "Not Found") EndIf Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Blue_Drache Posted October 2, 2007 Posted October 2, 2007 You cheated with RegExp(). Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
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