Jump to content

Autoit can get prompt in cmd window?


Recommended Posts

Hi All,

I'm trying to get the output from the cmd window. Like when I telnet some device and prompt user name and password, I can recognize them and input appropriate user name and password. I know perl and tcl could do it. But not sure Autoit can do this also?

Lou

Link to comment
Share on other sites

Hi All,

I'm trying to get the output from the cmd window. Like when I telnet some device and prompt user name and password, I can recognize them and input appropriate user name and password. I know perl and tcl could do it. But not sure Autoit can do this also?

Lou

By default, AutoIt compiles as a Windows GUI app. As such, it has no direct interface to the Console environment. You notice this when you run ConsoleRead() and ConsoleWrite() and nothing happens in the "DOS Box",

You could experiment with the compiler option (in the help file) to compile your script in CUI (Console User Interface) mode. ConsoleWrite() messages then go to the "DOS Box", though I'm not sure ConsoleRead() gets you the text from it.

Haven't had time to experiment with it, but I'm interested in the results.

:P

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

You could experiment with the compiler option (in the help file) to compile your script in CUI (Console User Interface) mode. ConsoleWrite() messages then go to the "DOS Box", though I'm not sure ConsoleRead() gets you the text from it.

I can't find anything about this CUI mode in the helpfile, but would need it as well...how to set it within the code?

We currently use "psinfo.exe -h" to get the list of installed MS-Hotfixes on out systems. Later versions of psinfo make problems on some of our systems. Therefor I'd like to replace it by a simple AutoIT command line tool that queries the cimv2 WMI provider...my code up to now is this:

;####################################################################
;#
;#  Christoph Herdeg, August 2008
;#  http://www.cs-it-solutions.de
;#
;####################################################################


; Declare the needed variables
; =====================================================================
Global $s_ComputerName = @ComputerName
Global $objWMIservice
Global $colItems
Global $objItem
Global $a_Text

; Set the WMI provider to \root\cimv2 of the local host
; =====================================================================
$objWMIservice = ObjGet("winmgmts:\\" & $s_ComputerName & "\root\cimv2")

; Do query items of class win32_quickfixengineering that start with the characters K or Q
; =====================================================================
If (IsObj($objWMIservice)) And (Not @error) Then
    $colItems = $objWMIservice.ExecQuery("SELECT * FROM win32_quickfixengineering WHERE HotFixId LIKE ""[KQ]%""")
    For $objItem In $colItems
        $a_Text &= "Patch ID: " & $objItem.HotFixId & @CRLF
    Next
EndIf   

; (hopefully som time soon) Writes ot the installed patches to the command line
; =====================================================================
; MsgBox("", "Installed Patches", "Installed Patches: " & @CRLF & $a_Text)
ConsoleWrite("Installed Patches: " & @CRLF & "===================" & @CRLF & $a_Text & @CRLF)

Thank you very much for a little bit of info...

Regards,

Chris

Edited by cherdeg
Link to comment
Share on other sites

Thanks all...searching might help sometimes...just add the following line to your code to get your ConsoleWrite() to DOS windows:

#AutoIt3Wrapper_Change2CUI=y

Regards,

Chris

Thanks for this tip. I tried to compile my script and run my .exe file. But it seems "telnet" command didn't execute. No any response from cosole window. ConsoleRead didn't caputre anything.

I replaced ConsoleRead() by StdinRead, still nothing captured:

#AutoIt3Wrapper_Change2CUI=y
#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c " & "telnet.exe", @SystemDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)
ConsoleWrite("open wodrivswt4" & @CR)
Local $data
While True
    $data &= StdoutRead($foo)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "Debug", $data)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...