coec Posted April 15, 2011 Share Posted April 15, 2011 Hi all I'm trying to automate the running of a .exe in a cmd box on Windows XP. I'm using AutoIt v3.3.6.1. The .exe I'm trying to run has several prompts and then at the end produces a line of text that I want to capture and write to a text file. The prompts consist of - Entering a string followed by pressing <ENTER> - Entering a type (single digit, automatically moves to next prompt) - Entering a type (single character, automatically moves to next prompt) - Entering a string followed by pressing <ENTER> - Entering a string followed by pressing <ENTER> At this point the string I want to capture is displayed. Any one got ideas on this? I've been breaking my brain on this for quite a while now. Thanks CC Link to comment Share on other sites More sharing options...
Newb Posted April 15, 2011 Share Posted April 15, 2011 You want infos on how to capture text over a prompt (cmd.exe) window or how to sends commands in it? I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
JScript Posted April 15, 2011 Share Posted April 15, 2011 1-) #AutoIt3Wrapper_Change2CUI=Y ;(Y/N) Change output program to CUI in stead of GUI. Default=N 2-) ;Function Reference StdoutRead() ;-------------------------------------------------------------------------------- ;Reads from the STDOUT stream of a previously run child process. StdoutRead( process_id[, peek = false[, binary = false]] ) http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
coec Posted April 15, 2011 Author Share Posted April 15, 2011 Apologies all, I should have posted my code initially. I see the prompt in step 1 and I try and send my response but I don't see the step 2 prompt so I don't think my response to step 1 is recognized. Also, the cmd box always GoesAway even though the exe is still running... I need to write to my.exe's Stdin and read from it's Stdout. The ConsoleWrite statements are effectively for debugging and will be removed. Attached is a sanitized view of what I've done so far --- #include <Constants.au3> #AutoIt3Wrapper_Change2CUI=Y local $pid = Run(@ComSpec & " /c " & "my.exe", "c:\users\bin", @SW_MAXIMIZE, 0x1 & 0x2) local $step = 1 $loop = 1 $line = "" local $char While $loop == 1 $line &= StdoutRead($pid) if $step == 1 Then If StringInStr($line, " prompt 1", 1) Then ConsoleWrite("Starting step 1 with $line = " & @CRLF & "'" & $line & "'" & @CRLF) Sleep(500) StdinWrite($pid, "String1" & @CRLF) ConsoleWrite("Finished step 1" & @CRLF) $step = 2 endif ElseIf $step == 2 Then If StringInStr($line, "you require", 1) Then StdinWrite($pid, "2") ConsoleWrite("Finished step 2 " & @CRLF & $line & @CRLF) $step = 3 endif ElseIf $step == 3 Then If StringInStr($line, "prompt 2", 1) Then StdinWrite($pid, "y") ConsoleWrite("Finished step 3 " & @CRLF & $line & @CRLF) $step = 4 endif ElseIf $step == 4 Then If StringInStr($line, "prompt 3", 1) Then StdinWrite($pid, "string 2" & @CRLF) ConsoleWrite("Finished step 4 " & @CRLF & $line & @CRLF) $step = 5 endif ElseIf $step == 5 Then If StringInStr($line, "(DD-MM-YYYY)", 1) Then StdinWrite($pid, "01-01-1900" & @CRLF) ConsoleWrite("Finished step 5 " & @CRLF & $line & @CRLF) $step = 6 endif ElseIf $step == 6 Then msgbox(0, "", @CRLF & @CRLF & $line & @CRLF) $loop = 0 EndIf WEnd --- Thanks CC Link to comment Share on other sites More sharing options...
JScript Posted April 15, 2011 Share Posted April 15, 2011 Next time post your code between the tags " " make it much easier the visualization... http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
coec Posted April 15, 2011 Author Share Posted April 15, 2011 expandcollapse popup#include <Constants.au3> #AutoIt3Wrapper_Change2CUI=Y local $pid = Run(@ComSpec & " /c " & "my.exe", "c:\users\bin", @SW_MAXIMIZE, 0x1 & 0x2) local $step = 1 $loop = 1 $line = "" local $char While $loop == 1 $line &= StdoutRead($pid) if $step == 1 Then If StringInStr($line, " prompt 1", 1) Then ConsoleWrite("Starting step 1 with $line = " & @CRLF & "'" & $line & "'" & @CRLF) Sleep(500) StdinWrite($pid, "String1" & @CRLF) ConsoleWrite("Finished step 1" & @CRLF) $step = 2 endif ElseIf $step == 2 Then If StringInStr($line, "you require", 1) Then StdinWrite($pid, "2") ConsoleWrite("Finished step 2 " & @CRLF & $line & @CRLF) $step = 3 endif ElseIf $step == 3 Then If StringInStr($line, "prompt 2", 1) Then StdinWrite($pid, "y") ConsoleWrite("Finished step 3 " & @CRLF & $line & @CRLF) $step = 4 endif ElseIf $step == 4 Then If StringInStr($line, "prompt 3", 1) Then StdinWrite($pid, "string 2" & @CRLF) ConsoleWrite("Finished step 4 " & @CRLF & $line & @CRLF) $step = 5 endif ElseIf $step == 5 Then If StringInStr($line, "(DD-MM-YYYY)", 1) Then StdinWrite($pid, "01-01-1900" & @CRLF) ConsoleWrite("Finished step 5 " & @CRLF & $line & @CRLF) $step = 6 endif ElseIf $step == 6 Then msgbox(0, "", @CRLF & @CRLF & $line & @CRLF) $loop = 0 EndIf WEnd Link to comment Share on other sites More sharing options...
JScript Posted April 15, 2011 Share Posted April 15, 2011 (edited) You could have edited the previous post: Well, without having your "My.exe" is a bit hard to help you...I can not reproduce the effect you want! Edited April 15, 2011 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
coec Posted April 15, 2011 Author Share Posted April 15, 2011 I can't post my.exe as it requires a whole bunch of DLLs and its internal proprietary software and I don't have access to the source. I tried editing my previous post but it told my I didn't have permission. I don't see '#AutoIt3Wrapper_Change2CUI' in the help file... Does the example above look at least vaguely sane? I've only been using AutoIt for 1 day... CC Link to comment Share on other sites More sharing options...
JScript Posted April 15, 2011 Share Posted April 15, 2011 I can't post my.exe as it requires a whole bunch of DLLs and its internal proprietary software and I don't have access to the source. I tried editing my previous post but it told my I didn't have permission.I don't see '#AutoIt3Wrapper_Change2CUI' in the help file...Does the example above look at least vaguely sane? I've only been using AutoIt for 1 day...CCToo bad...#AutoIt3Wrapper_Change2CUI in SciTE -> Help --> SciTE Help http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
ripdad Posted April 15, 2011 Share Posted April 15, 2011 Main problem in your script: 0x1 & 0x2 -> Should be 0x1 + 0x2 or -> 0x3 I have no way to test it .. but this should get you closer. expandcollapse popup#include <Constants.au3> #AutoIt3Wrapper_Change2CUI=Y Local $char, $step = 1, $line = "" Local $pid = Run(@ComSpec & " /c my.exe", "c:\users\bin", @SW_MAXIMIZE, 0x3) While 1 $line &= StdoutRead($pid, 0, 0) If @error Then ExitLoop Sleep(10) If $step = 1 Then If StringInStr($line, "prompt 1") Then ConsoleWrite("Starting step 1 with $line = " & @CRLF & "'" & $line & "'" & @CRLF) Sleep(500) StdinWrite($pid, "String1" & @CRLF) ConsoleWrite("Finished step 1" & @CRLF) $step = 2 EndIf ElseIf $step = 2 Then If StringInStr($line, "you require") Then StdinWrite($pid, "2") ConsoleWrite("Finished step 2 " & @CRLF & $line & @CRLF) $step = 3 EndIf ElseIf $step = 3 Then If StringInStr($line, "prompt 2") Then StdinWrite($pid, "y") ConsoleWrite("Finished step 3 " & @CRLF & $line & @CRLF) $step = 4 EndIf ElseIf $step = 4 Then If StringInStr($line, "prompt 3") Then StdinWrite($pid, "string 2" & @CRLF) ConsoleWrite("Finished step 4 " & @CRLF & $line & @CRLF) $step = 5 EndIf ElseIf $step = 5 Then If StringInStr($line, "(DD-MM-YYYY)") Then StdinWrite($pid, "01-01-1900" & @CRLF) ConsoleWrite("Finished step 5 " & @CRLF & $line & @CRLF) $step = 6 EndIf ElseIf $step = 6 Then MsgBox(0, "", @CRLF & @CRLF & $line & @CRLF) ExitLoop EndIf WEnd "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward 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