Jump to content

Clearing a cmd screen with consolewrite()?


Recommended Posts

First your writing to the autoit screen and that is it, even if you execute it from the command line ConsoleWrite doesn't work that way.

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

Link to comment
Share on other sites

Here's a better way to clear the console (when running in cmd.exe that is)

Global Const $STD_OUTPUT_HANDLE = 2^32-11
Global Const $CONSOLE_SCREEN_BUFFER_INFO = "short dwSizeX;short dwSizeY;short dwCursorPositionX;short dwCursorPositionY;" & _
        "ushort wAttributes;short srWindowLeft;short srWindowTop;short srWindowRight;short srWindowBottom;" & _
        "short dwMaximumWindowSizeX;short dwMaximumWindowSizeY;"




Func _ClearConsole()

    $hConsole = DllCall("Kernel32.dll", "ptr", "GetStdHandle", "dword", $STD_OUTPUT_HANDLE)
    $hConsole = $hConsole[0]

    $csbi = DllStructCreate($CONSOLE_SCREEN_BUFFER_INFO)
    $call = DllCall("Kernel32.dll", "int", "GetConsoleScreenBufferInfo", "ptr", $hConsole, "ptr", DllStructGetPtr($csbi))


    $call = DllCall("Kernel32.dll", "int", "FillConsoleOutputCharacterW", "ptr", $hConsole, "short", 0, _
            "dword", DllStructGetData($csbi, "dwSizeX") * DllStructGetData($csbi, "dwSizeY"), "dword", 0, "dword*", 0)


    $call = DllCall("Kernel32.dll", "int", "CloseHandle", "ptr", $hConsole)

EndFunc  ;==>_ClearConsole

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Here's a better way to clear the console (when running in cmd.exe that is)

Global Const $STD_OUTPUT_HANDLE = 2^32-11
 Global Const $CONSOLE_SCREEN_BUFFER_INFO = "short dwSizeX;short dwSizeY;short dwCursorPositionX;short dwCursorPositionY;" & _
         "ushort wAttributes;short srWindowLeft;short srWindowTop;short srWindowRight;short srWindowBottom;" & _
         "short dwMaximumWindowSizeX;short dwMaximumWindowSizeY;"
 
 
 
 
 Func _ClearConsole()
 
     $hConsole = DllCall("Kernel32.dll", "ptr", "GetStdHandle", "dword", $STD_OUTPUT_HANDLE)
     $hConsole = $hConsole[0]
 
     $csbi = DllStructCreate($CONSOLE_SCREEN_BUFFER_INFO)
     $call = DllCall("Kernel32.dll", "int", "GetConsoleScreenBufferInfo", "ptr", $hConsole, "ptr", DllStructGetPtr($csbi))
 
 
     $call = DllCall("Kernel32.dll", "int", "FillConsoleOutputCharacterW", "ptr", $hConsole, "short", 0, _
             "dword", DllStructGetData($csbi, "dwSizeX") * DllStructGetData($csbi, "dwSizeY"), "dword", 0, "dword*", 0)
 
 
     $call = DllCall("Kernel32.dll", "int", "CloseHandle", "ptr", $hConsole)
 
 EndFunc ;==>_ClearConsole
Have a look at post #15, you need to add a lot more lines to compete with Rover.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

But I still dont understand why my method works so well.

You would think that using the run command would start a NEW instance of cmd, not send commands to the currently open one. It just doesnt make sence.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

But I still dont understand why my method works so well.

You would think that using the run command would start a NEW instance of cmd, not send commands to the currently open one. It just doesnt make sence.

It's very simple, you can even write cls.exe for yourself. What it does is attaching to the console of the parent process (which in this case is your script) and then use a method similar to Rover's and mine.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Ah I see. Thank you. :P

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

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