Sign in to follow this  
Followers 0
Zohar

[Solved] ConsoleWrite() in a DOS (Command Prompt) Window

12 posts in this topic

#1 ·  Posted (edited)

Hi

 

I am using windows XP SP3.

 

I created a very short AutoIt script, containing only this single line:

ConsoleWrite("Hello")

I compiled it using F7, and then opened a DOS window, and ran the EXE file...

I get nothing..

Why is that?

 

(The "Hello" string successfully appear in the bottom part of the SciTE window, when I run the Au3 file in scite via F5)

 

Thank you

Edited by Zohar

Share this post


Link to post
Share on other sites



#AutoIt3Wrapper_Change2CUI=Y

is your friend. You need the full SciTE package installed.

 

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Hi UEZ

 

Thank you..

 

If I don't have the full SCiTE Package, then there's no other way that I can achieve it?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You have to patch the exe manually. As far as I can remember one byte must be changed.

Going to test it ...

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Use the proper #pragma() statement to set it to produce a Console Exe.

#pragma compile(Console, true)

Jos

Edited by Jos
1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you very much UEZ and Jos

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I tested this now:

Use the proper #pragma() statement to set it to produce a Console Exe.

#pragma compile(Console, true)

Jos

 

It compiles well,

but still nothing is written to the DOS window.

ConsoleWrite() writes successfully to SciTE's console window, but not to a DOS window when the program is ran in DOS..

 

Might it be because I am using AutoIt v3.3.6.1?

Edited by Zohar

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I tested this now:

 

It compiles well,

but still nothing is written to the DOS window.

ConsoleWrite() writes successfully to SciTE's console window, but not to a DOS window when the program is ran in DOS..

 

Might it be because I am using AutoIt v3.3.6.1?

#pragma is not implemented until 3.3.9.13 I believe, so guess they might be a problem!

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You can change your app using this function ;)

#include <WinAPI.au3>

Global Const $IMAGE_SUBSYSTEM_WINDOWS_GUI = 2
Global Const $IMAGE_SUBSYSTEM_WINDOWS_CUI = 3

Global Const $tagIMAGE_DOS_HEADER = 'ushort e_magic; ushort LastPageBytes; ushort PagesInFile; ushort Relocs; ushort HeaderSizep; ushort e_minalloc; ushort e_maxalloc; ushort e_ss; ushort e_sp; ushort Checksum; ushort e_ip; ushort e_cs; ushort RelocTableOffset; ushort Overlay; ushort ReservedWords[4]; ushort e_oemid; ushort e_oeminfo; ushort ReservedWords[10]; long CoffHeaderOffset'

Global $sExe = "YourApp.exe"

Global $Success = _Win32SubsystemSwitch($sExe, $IMAGE_SUBSYSTEM_WINDOWS_CUI)
MsgBox(0, "Subsystem-Patcher", _
        "Filename: " & $sExe & @CRLF & _
        "Success: " & $Success & @CRLF & _
        "Error: " & @error & @CRLF & _
        "File changed: " & @extended)


Func _Win32SubsystemSwitch($sPE_File_Path, $Subsystem, $MakeBackupCopy = True)
    ;funkey 2015.03.13
    Local $hFile = _WinAPI_CreateFile($sPE_File_Path, 2, 6, 2)
    If $hFile = 0 Then Return SetError(1, 0, False)

    Local $tIMAGE_DOS_HEADER = DllStructCreate($tagIMAGE_DOS_HEADER)
    Local $iBytesRead = 0, $iBytesWritten = 0

    If Not _WinAPI_ReadFile($hFile, DllStructGetPtr($tIMAGE_DOS_HEADER), DllStructGetSize($tIMAGE_DOS_HEADER), $iBytesRead) Then
        _WinAPI_CloseHandle($hFile)
        Return SetError(2, 0, False)
    EndIf

    If $iBytesRead <> DllStructGetSize($tIMAGE_DOS_HEADER) Then
        _WinAPI_CloseHandle($hFile)
        Return SetError(3, 0, False)
    EndIf

    _WinAPI_SetFilePointer($hFile, DllStructGetData($tIMAGE_DOS_HEADER, "CoffHeaderOffset") + 92)

    Local $tSubsystem = DllStructCreate("USHORT Subsystem")

    If Not _WinAPI_ReadFile($hFile, DllStructGetPtr($tSubsystem), DllStructGetSize($tSubsystem), $iBytesRead) Then
        _WinAPI_CloseHandle($hFile)
        Return SetError(4, 0, False)
    EndIf

    Local $Current_Subsystem = DllStructGetData($tSubsystem, "Subsystem")

    If $Current_Subsystem = $Subsystem Then
        _WinAPI_CloseHandle($hFile)
        Return SetError(0, 0, True)
    EndIf

    If $Current_Subsystem <> $IMAGE_SUBSYSTEM_WINDOWS_GUI And $Current_Subsystem <> $IMAGE_SUBSYSTEM_WINDOWS_CUI Then
        _WinAPI_CloseHandle($hFile)
        Return SetError(5, 0, False)
    EndIf

    _WinAPI_SetFilePointer($hFile, DllStructGetData($tIMAGE_DOS_HEADER, "CoffHeaderOffset") + 92)

    DllStructSetData($tSubsystem, "Subsystem", $Subsystem)

    If $MakeBackupCopy Then
        Local $sBackupFile, $num = 1
        Do
            $sBackupFile = StringFormat("%s (%03i).bak", $sExe, $num)
            $num += 1
        Until Not FileExists($sBackupFile)
        FileCopy($sExe, $sBackupFile)
    EndIf

    If Not _WinAPI_WriteFile($hFile, DllStructGetPtr($tSubsystem), DllStructGetSize($tSubsystem), $iBytesWritten) Then
        _WinAPI_CloseHandle($hFile)
        Return SetError(6, 0, True)
    EndIf

    _WinAPI_CloseHandle($hFile)
    Return SetError(0, 1, True)
EndFunc   ;==>_Win32SubsystemSwitch

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

#pragma is not implemented until 3.3.9.13 I believe, so guess they might be a problem!

Jos

 

 

You can change your app using this function ;)

Thank you funkey

This whole function is needed just to make it work?

Is that also what "#pragma compile(Console, true)" and "#AutoIt3Wrapper_Change2CUI=Y" are adding to the compiled file?

 

And BTW is the solution that UEZ offered also possible?

You have to patch the exe manually. As far as I can remember one byte must be changed.

Going to test it ...

 

Edited by Zohar

Share this post


Link to post
Share on other sites

This function is needed if the application is already compiled and you want to change the subsystem (Gui or Cui). The right way is to compile the application with the right settings using the #pragma or #AutoIt3Wrapper directives.

The function changes the byte (word) UEZ mentioned.


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

Oh

So this function is for cases where I already compiled my program without the right switch.. OK.

Thank you very much

Share this post


Link to post
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
Sign in to follow this  
Followers 0