jesternaut Posted December 11, 2007 Share Posted December 11, 2007 I have an executable with a parameter that I need to run to get the response text. I redirect it to a text file then I use filereadline to read in each line and stringInStr to look for the string "Changer". but when I run this the tapetest.txt is not generated. I don't think the parameter is being read. If I run the exectable and the parameter in a shell it works.I have tried the shellexecute, and the run commands using the @stdio_child. I have gone so far as to create a bat file that runs the shell commands when called and called it via a run command inside the script. If I run it in a shell it runs but not from the Autoit script. The code is...Func is_changer(); this function checks if a changer is connected;This will generate a file with the output from the ca_devmgr -adapterinfo commandRunWait("C:\Program Files\CA\BrightStor ARCserve Backup\ca_devmgr -adapterinfo > tapetest.txt")MsgBox(0, "check point 1:", "Is the tapetest.txt there")$file = FileOpen("C:\Program Files\CA\BrightStor ARCserve Backup\tapetest.txt", 0); Check if file opened for reading OKIf $file = -1 Then MsgBox(0, "Error", "Unable to open file.") ExitEndIf; Read in lines of text until the EOF is reachedWhile 1 $result = "" ;reset result back to blank $line = FileReadLine($file) If @error = -1 Then ExitLoop ;MsgBox(0, "Line read:", $line) $result = StringInStr($line, "Changer") If $result <> 0 Then ;if true means a changer was found $changer = "0" ;0 indicates the changer exists MsgBox(0, "changer found:", "The $changer result is " & $line) ExitLoop EndIfWendFileClose($file)FileDelete("C:\Program Files\CA\BrightStor ARCserve Backup\tapetest.txt") ; Shows the GUI after the function completesGUISetState(@SW_SHOW)EndFuncI would love a simpler way to get the response from the executable. But when I run this the tapetest.txt is not generated. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 11, 2007 Share Posted December 11, 2007 Try it this way and see if that isn't a little easier: #include <Constants.au3> Local $sDir = "C:\Program Files\CA\BrightStor ARCserve Backup" Local $sExe = "ca_devmgr -adapterinfo" Local $sOutput = "" Local $PID = Run($sDir & "\" & $sExe, $sDir, @SW_MINIMIZE, $STDOUT_CHILD + $STDERR_CHILD) Do Sleep(20) If StdoutRead($PID, 0, 1) Then $sOutput &= StdoutRead($PID) If StderrRead($PID, 0, 1) Then $sOutput &= StderrRead($PID) Until Not ProcessExists($PID) If StringInStr($sOutput, "changer") Then MsgBox(64, "Changer Detected", $sOutput) Else MsgBox(16, "No Changer Detected", $sOutput) EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jesternaut Posted December 12, 2007 Author Share Posted December 12, 2007 I have an executable with a parameter that I need to run to get the response text. I redirect it to a text file then I use filereadline to read in each line and stringInStr to look for the string "Changer". but when I run this the tapetest.txt is not generated. I don't think the parameter is being read. If I run the exectable and the parameter in a shell it works.I have tried the shellexecute, and the run commands using the @stdio_child. I have gone so far as to create a bat file that runs the shell commands when called and called it via a run command inside the script. If I run it in a shell it runs but not from the Autoit script. The code is...Func is_changer(); this function checks if a changer is connected;This will generate a file with the output from the ca_devmgr -adapterinfo commandRunWait("C:\Program Files\CA\BrightStor ARCserve Backup\ca_devmgr -adapterinfo > tapetest.txt")MsgBox(0, "check point 1:", "Is the tapetest.txt there")$file = FileOpen("C:\Program Files\CA\BrightStor ARCserve Backup\tapetest.txt", 0); Check if file opened for reading OKIf $file = -1 Then MsgBox(0, "Error", "Unable to open file.") ExitEndIf; Read in lines of text until the EOF is reachedWhile 1 $result = "" ;reset result back to blank $line = FileReadLine($file) If @error = -1 Then ExitLoop ;MsgBox(0, "Line read:", $line) $result = StringInStr($line, "Changer") If $result <> 0 Then ;if true means a changer was found $changer = "0" ;0 indicates the changer exists MsgBox(0, "changer found:", "The $changer result is " & $line) ExitLoop EndIfWendFileClose($file)FileDelete("C:\Program Files\CA\BrightStor ARCserve Backup\tapetest.txt") ; Shows the GUI after the function completesGUISetState(@SW_SHOW)EndFuncI would love a simpler way to get the response from the executable. But when I run this the tapetest.txt is not generated. Link to comment Share on other sites More sharing options...
jesternaut Posted December 12, 2007 Author Share Posted December 12, 2007 That did the trick. Thanks sooooo much. 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