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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

So we have confirmed that I was wrong.

But as to the HelpFile

  On 1/19/2021 at 2:40 PM, 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.

Expand  

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

Expand  

 

Maybe there should be also mentioned something like this"

  Quote

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

Expand  

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 1/19/2021 at 6:36 PM, mLipok said:

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

Expand  

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:

  Reveal hidden contents

Signature last update: 2023-04-24

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

A new quick/small UDF.

Expand  

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