Jump to content

Recommended Posts

Posted

btw... I would like to propose your example in this form:

_Example_Nine()

Func _Example_Nine()

    #REMARK !!!   True or true as Boolean is converted internaly to "True" as string

    ConsoleWrite("( bool vs string true ) = " & (True == "True") & @CRLF) ; Positive result because Boalean True is converted so .... "True" == "True"
    ConsoleWrite("( bool vs string true ) = " & (true == "true") & @CRLF) ; Negative result because Boalean true is converted so .... "True" <> "true"
    ConsoleWrite(@CRLF)

    ConsoleWrite("( string True vs Bool ) = " & ("True" == True) & @CRLF) ; Positive result because Boalean True is converted so .... "True" == "True"
    ConsoleWrite("( string True vs Bool ) = " & ("True" == true) & @CRLF) ; Positive result because Boalean true is converted so .... "True" == "True"
    ConsoleWrite(@CRLF)

    ConsoleWrite("( string true vs Bool ) = " & ("true" == True) & @CRLF) ; Negative result because Boalean True is converted so .... "true" <> "True"
    ConsoleWrite("( string true vs Bool ) = " & ("true" == true) & @CRLF) ; Negative result because Boalean true is converted so .... "true" <> "True"
    ConsoleWrite(@CRLF)

EndFunc   ;==>_Example

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

So we have confirmed that I was wrong.

But as to the HelpFile

3 hours ago, FrancescoDiMuro said:

as stated in the Help file about == operator:

Quote

Tests if two strings are equal. Case-sensitive. The left and right values are converted to strings if they are not strings already. This operator should only be used if string comparisons need to be case-sensitive.

So, you are not asserting that $bReset is bool, indeed, you are converting both sides to strings, isn't it?

 

Maybe there should be also mentioned something like this"

Quote

Booleans are always converted to capitalized strings: "True" or "False".

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
33 minutes ago, mLipok said:

Booleans are always converted to capitalized strings: "True" or "False".

Even though we have no proof of this, I admit your interpretation makes more sense than mine.  This tends also to confirm your statement :

ConsoleWrite (String(true) & @CRLF)
ConsoleWrite (String(false) & @CRLF)

 

Posted

New version in OpeningPost.

 

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

  • 1 month later...
Posted (edited)
On 1/19/2021 at 6:46 AM, mLipok said:

A new quick/small UDF.

and now with errorlevel return :) 

#include-once
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Global $RUN_WRAPPER_PID, $RUN_WRAPPER_HANDLE, $RUN_WRAPPER_EXITCODE
Global Enum _
        $RUNWRAPPER_ERR_SUCCESS, _
        $RUNWRAPPER_ERR_GENERAL, _
        $RUNWRAPPER_ERR_COUNTER

Global Enum _
        $RUNWRAPPER_EXT_DEFAULT, _
        $RUNWRAPPER_EXT_NOT_FINISHED_YET, _
        $RUNWRAPPER_EXT_COUNTER

If Not @Compiled And @ScriptName = 'Run_Wrapper.au3' Then _Example_for_Run_Wrapper()

Func _Example_for_Run_Wrapper() ; https://www.autoitscript.com/forum/topic/204931-run_wrapperau3-udf-support-topic/
    _Run_Wrapper('ping 8.8.8,8')
    If @error Then Return SetError(@error, @extended, 0)
    While $RUN_WRAPPER_PID
        Sleep(10)
        _Run_Wrapper_GetStdout()
        If @error Then
            _Run_Wrapper_GetStderr()
            If @error Then ExitLoop
        EndIf
    WEnd
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, 'Information #' & @ScriptLineNumber, _
            _Run_Wrapper_GetStdout() & @CRLF & _
            _Run_Wrapper_GetStderr() & @CRLF & _
            'ExitCode: ' & _Run_Wrapper_GetExitCode() _
            )

EndFunc   ;==>_Example_for_Run_Wrapper

Func _Run_Wrapper($sCommand, $sWorkingDir = @TempDir, $iShowFlag = @SW_HIDE)
    $RUN_WRAPPER_HANDLE = 0 ;               @TempDir is better than @SystemDir. "Echo text > here.txt"
    _Run_Wrapper_GetStdout(Null)
    _Run_Wrapper_GetStderr(Null)
    $RUN_WRAPPER_PID = Run(@ComSpec & " /c " & $sCommand, $sWorkingDir, $iShowFlag, $STDERR_CHILD + $STDOUT_CHILD)
    If @error Then Return SetError($RUNWRAPPER_ERR_GENERAL, $RUNWRAPPER_EXT_DEFAULT, 0)
    _Run_Wrapper_GetExitCode(Null)
    Return $RUN_WRAPPER_PID
EndFunc   ;==>_Run_Wrapper

Func _Run_Wrapper_GetStdout($v_Reset = Default)
    Local Static $iError, $s_StdOut = ""
    If IsKeyword($v_Reset) And $v_Reset = Null Then $s_StdOut = ''
    $s_StdOut &= StdoutRead($RUN_WRAPPER_PID)
    $iError = @error
    If $iError Then
        _Run_Wrapper_GetExitCode() ; it will only close the OpenProcess if not STILL_ACTIVE
        Return SetError($iError, $RUNWRAPPER_EXT_DEFAULT, $s_StdOut)
    EndIf
    Return SetExtended($RUNWRAPPER_EXT_NOT_FINISHED_YET, $s_StdOut)
EndFunc   ;==>_Run_Wrapper_GetStdout

Func _Run_Wrapper_GetStderr($v_Reset = Default)
    Local Static $iError, $s_StdErr = ''
    If IsKeyword($v_Reset) And $v_Reset = Null Then $s_StdErr = ''
    $s_StdErr &= StderrRead($RUN_WRAPPER_PID)
    $iError = @error
    If $iError Then
        _Run_Wrapper_GetExitCode() ; it will only close the OpenProcess if not STILL_ACTIVE
        Return SetError($iError, $RUNWRAPPER_EXT_DEFAULT, $s_StdErr)
    EndIf
    Return SetExtended($RUNWRAPPER_EXT_NOT_FINISHED_YET, $s_StdErr)
EndFunc   ;==>_Run_Wrapper_GetStderr

Func _Run_Wrapper_GetExitCode($v_Do = Default) ; based on AutoIt3Wrapper
    If $v_Do = Null Then
        If IsArray($RUN_WRAPPER_HANDLE) Then __Run_Wrapper_ProcessCloseHandle($RUN_WRAPPER_HANDLE)
        $RUN_WRAPPER_HANDLE = 0
    EndIf
    Local $aRet, $v_Placeholder
    If Not IsArray($RUN_WRAPPER_HANDLE) Then
        If $v_Do = Default Then Return $RUN_WRAPPER_EXITCODE
        $RUN_WRAPPER_EXITCODE = 0
        ; Set/Return the process handle of a PID
        $RUN_WRAPPER_HANDLE = DllCall('kernel32.dll', 'ptr', 'OpenProcess', 'int', 0x400, 'int', 0, 'int', $RUN_WRAPPER_PID)
        If Not @error Then
            Return $RUN_WRAPPER_HANDLE
        Else
            $RUN_WRAPPER_HANDLE = 0
        EndIf
    Else
        ; Set Process Exitcode of PID
        $aRet = DllCall('kernel32.dll', 'ptr', 'GetExitCodeProcess', 'ptr', $RUN_WRAPPER_HANDLE[0], 'int*', $v_Placeholder)
        If Not @error And UBound($aRet) > 2 Then $RUN_WRAPPER_EXITCODE = $aRet[2]

        ; https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodeprocess
        ; STILL_ACTIVE = 259
        If $RUN_WRAPPER_EXITCODE <> 259 Then
            If __Run_Wrapper_ProcessCloseHandle($RUN_WRAPPER_HANDLE) Then
                $RUN_WRAPPER_PID = 0
                $RUN_WRAPPER_HANDLE = 0
            EndIf
        EndIf
    EndIf
    Return $RUN_WRAPPER_EXITCODE
EndFunc   ;==>_Run_Wrapper_GetExitCode

Func __Run_Wrapper_ProcessCloseHandle($h_Process)  ; from AutoIt3Wrapper
    DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $h_Process)
    If Not @error Then Return 1 ; Close the process handle of a PID
    Return 0
EndFunc   ;==>__Run_Wrapper_ProcessCloseHandle

 

Edited by argumentum
coded to better fit the idea

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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
×
×
  • Create New...