Jump to content

Can you PEEK without hiding text in the console?


Recommended Posts

I want to have the AutoIT script read the contents of the CMD window without removing it from the window.

The following is the contents of C:\Temp\Test1.bat:

@echo off
echo.
echo Line one.
echo.
echo Line two.
echo.
echo Done.
echo.
pause

The text remains in the CMD window if I run it like this:

$BatFile = "C:\Temp\Test1.bat"
Run($BatFile, @TempDir, @SW_SHOW)oÝ÷ Ø­ò0j{lyëaz×±¶)æÊÇ+H®éíçèZ0xºÚ"µÍÈÝÝÝ]XY

BÚ[ÛYIÐÛÛÝ[Ë]LÉÝÂÈ[H]Ú[BÌÍÐ][HH  ][ÝÐÎÌLÕ[  ÌLÕÝK]   ][ÝÂÌÍÚØÈH[  ÌÍÐ][K[Õ×ÔÒÕË  ÌÍÔÕÕUÐÒS
BÚ[HBRYÝ[Ò[ÝÝÝ]XY
    ÌÍÚØËLKJK  ][ÝÔÜÈ[HÙ^HÈÛÛ[YI][ÝÊH[BSÙÐÞ
    ][ÝÕÝI][ÝË ÌÎNÔØ]È    ][ÝÔÜÈ[HÙ^HÈÛÛ[YI][ÝÈ^ÌÎNÊBQ[YTÛY
L
BÑ[

The problem is, the script sees the text, but it's gone from the CMD window, even though I'm using the PEEK option. Is it not possible to monitor the output from the CMD window without removing it from the window?

:P

Edit: Took out $STDIN_CHILD... seperate topic.

Edited by PsaltyDS
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

I don't think you can pipe your STDOUT and eat it too. BUT, you could make a pretend command console, like this:

#include <GUIConstants.au3>
#include <Constants.au3>


GUICreate("Command Prompt",668,331,-1,-1)  ; will create a dialog box that when displayed is centered

$cmd=GUICtrlCreateEdit ("C:>"& @CRLF, 0,0,668,331,$ES_AUTOVSCROLL+$WS_VSCROLL)
GUICtrlSetFont (-1, 12 , 800, -1 , "Terminal")
GUICtrlSetColor ( -1, 0xc3c3c3)
GUICtrlSetBkColor ( -1, 0x000000)

GUISetState ()

$foo = Run(@ComSpec & " /c dir ", "C:\", @SW_HIDE, $STDOUT_CHILD)
$output = ""
$display = ""
$found = 0
While 1
    $output &= StdoutRead($foo)
    if $display <> $output Then
        $display = $output
        GUICtrlSetData ($cmd, $display)
    EndIf
    If @error Then ExitLoop
    
    If StringInStr($display, "Windows") and $found = 0 Then
        $found = 1
        MsgBox(64, "Test1", 'Saw "Windows"!')
    EndIf
Wend

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

I like pretending.

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

I don't think you can pipe your STDOUT and eat it too. BUT, you could make a pretend command console, like this:

...

I like pretending.

I was afraid of that... :P

What I really want is the equivelent of the Unix/Linux tee command, but working both ways. StdOutRead() and StdInWrite() are not getting it, because they cripple the the console window by attaching to it. The funky way Windows handles console windows seems to almost intentionally frustrate that.

I did find an open sourced remix of tee for Win32 as part of UnxUtils. Work on that project seems to have been abandoned in 2004, but I downloaded it and it still works on XP SP2. This may take care of the output side, still in limbo on the input side.

:)

P.S. I like your "pretend" console window idea, it just won't handle the installer I'm dealing with right now... :nuke:

Edited by PsaltyDS
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 know, Windows provides a mechanism to handle this sort of thing, provided you already know what the questions will be, the order they'll be in, and your answer. Consider the following batch script INSTALLER.BAT:

dir C:\
pause
echo You pressed any key!

You run that, and you'll have to press something to make it do the echo, right? Okay, now create a file called SCRIPT.TXT:

y

Now run this command:

INSTALLER.BAT < SCRIPT.TXT

Maybe that will work for you. If you need something dynamic, well, I'm not sure about that...

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

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...