Jump to content

Recommended Posts

Posted (edited)

Good afternoon,

 

I realized that when a script performs a lot of processing, it hangs, such as the below program. Can you solve this?

#include <Array.au3>

Break (0)

Local $matriz_aplicativos [6] = [ "*zunemusic*"           _    ; Groove Música
                                , "*solitairecollection*" _    ; Microsoft Solitaire Collection
                                , "*zunevideo*"           _    ; Filmes e TV
                                , "*xbox*"                   _    ; Xbox Console Companion e Xbox Game Bar
                                , "*officehub*"           _    ; Office
                                , "*skypeapp*"               ] ; Skype
_ArrayAdd ( $matriz_aplicativos , "*HPAudioControl*"       ) ; HP Audio Control
_ArrayAdd ( $matriz_aplicativos , "*HPSystemInformation*" ) ; HP System Information

For $indice_aplicativo = 0 To UBound ( $matriz_aplicativos ) - 1
    For $num = 1 To 10
        Executa_dos_4 ( "powershell.exe -command ""Get-AppXPackage " & $matriz_aplicativos [$indice_aplicativo] _
                      & " | Remove-AppXPackage""" , "" , "" )
    Next
Next

MsgBox(262144,"","End")

; ============================================
; Função que executa um comando DOS - versão 4
; ============================================

Func Executa_dos_4 ( $comando , $workdir , $funcao )

    $pid        = Run ( @ComSpec & " /c " & $comando , $workdir , @SW_HIDE , $STDERR_CHILD + $STDOUT_CHILD )
    $resultado = ""
    $erro       = ""

    While 1
        If $funcao <> "" Then Call ( $funcao )
        $resultado = $resultado & StdoutRead ( $pid )
        $erro        = $erro        & StderrRead ( $pid )
        If @error Then
            StdioClose ( $pid )
            Return        ( _OemToStr ( $resultado & "|" & $erro ) )
        EndIf
    WEnd

EndFunc

; =========================================================
; Função que corrige um texto com caracteres fora do padrão
; =========================================================

Func _OemToStr ( $sOEM , $iCodepage = Default )

    If $iCodepage = Default Then
        $iCodepage = Int ( RegRead ( "HKLM\SYSTEM\CurrentControlSet\Control\Nls\Codepage" , "OEMCP" ) )
    EndIf

    Local              $tText   = DllStructCreate ( "byte[" & StringLen ( $sOEM ) & "]" )
    DllStructSetData ( $tText , 1 , $sOEM )
    Local              $aResult = DllCall ( "kernel32.dll" , "int" , "MultiByteToWideChar" , "uint" _
                                        , $iCodepage , "dword" , 0 , "struct*" , $tText , "int" _
                                        , StringLen ( $sOEM ) , "ptr" , 0 , "int" , 0 ) , _
                     $tWstr   = DllStructCreate ("wchar[" & $aResult [0] & "]" )
                     $aResult = DllCall ( "kernel32.dll" , "int" , "MultiByteToWideChar" , "uint" _
                                        , $iCodepage , "dword" , 0 , "struct*" , $tText , "int" _
                                        , StringLen ( $sOEM ), "struct*" , $tWstr , "int" , $aResult [0] )
    Return              DllStructGetData ( $tWstr , 1 )

EndFunc

 

 

Edited by Jos
Place the script on the topic body.
  • Developers
Posted
  • Why not simply post the code in a Code-Box (<>) in the post?
  • What exactly are you expecting when you insist in capturing the process output?
  • What exactly is it you like to be able to do when these processes are running?

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

I did not find Code Box. I put it on the body of the topic.
This is just a generic example to demonstrate the lock, I use the "execute_dos_4" function for various things.

  • Developers
Posted

I updated your first post to include the codebox which you still had forgotten. ;) 

Now try to answer my other questions as you still haven't explained when it is you expect the code to do.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@Darien

no hang you say's:

#include <Array.au3>

Break(0)

Local $matriz_aplicativos[6] = ["*zunemusic*" _                ; Groove Música
        , "*solitairecollection*" _                            ; Microsoft Solitaire Collection
        , "*zunevideo*" _                                      ; Filmes e TV
        , "*xbox*" _                                              ; Xbox Console Companion e Xbox Game Bar
        , "*officehub*" _                                      ; Office
        , "*skypeapp*"]                                        ; Skype
_ArrayAdd($matriz_aplicativos, "*HPAudioControl*")           ; HP Audio Control
_ArrayAdd($matriz_aplicativos, "*HPSystemInformation*")     ; HP System Information

For $indice_aplicativo = 0 To UBound($matriz_aplicativos) - 1
    For $num = 1 To 10
        Executa_dos_4('"powershell Get-AppXPackage "' & $matriz_aplicativos[$indice_aplicativo] _
                 & '" | Remove-AppXPackage"', "", "")
    Next
Next

MsgBox(262144, "", "End")

; ============================================
; Função que executa um comando DOS - versão 4
; ============================================

Func Executa_dos_4($comando, $workdir, $funcao)

    $pid = Run(@ComSpec & " /c " & $comando, $workdir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    $resultado = ""
    $erro = ""

    While 1
        If $funcao <> "" Then Call($funcao)
        $resultado = $resultado & StdoutRead($pid)
        $erro = $erro & StderrRead($pid)
        If @error Then
            StdioClose($pid)
            Return(_OemToStr($resultado & "|" & $erro))
        EndIf
    WEnd

EndFunc   ;==>Executa_dos_4

; =========================================================
; Função que corrige um texto com caracteres fora do padrão
; =========================================================

Func _OemToStr($sOEM, $iCodepage = Default)

    If $iCodepage = Default Then
        $iCodepage = Int( RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Nls\Codepage", "OEMCP"))
    EndIf

    Local $tText = DllStructCreate("byte[" & StringLen($sOEM) & "]")
    DllStructSetData($tText, 1, $sOEM)
    Local $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint" _
            , $iCodepage, "dword", 0, "struct*", $tText, "int" _
            , StringLen($sOEM), "ptr", 0, "int", 0), _
            $tWstr = DllStructCreate("wchar[" & $aResult[0] & "]")
    $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint" _
            , $iCodepage, "dword", 0, "struct*", $tText, "int" _
            , StringLen($sOEM), "struct*", $tWstr, "int", $aResult[0])
    Return DllStructGetData($tWstr, 1)

EndFunc   ;==>_OemToStr

 

none

Posted (edited)

I want to capture the out of the process to know the result of a command DOS. For example:

If StringInStr ( Executa_dos_4 ( "wmic qfe get hotfixid" , "" , "" ) , "4493441" ) Then

If StringInStr ( Executa_dos_4 ( "devcon status @"  & $ID , $pasta_devcon , "" ) , "Device is disabled" ) Then

If StringInStr ( Executa_dos_4 ( "sc query spooler" , "" , "" ) , "RUNNING" ) Then

 

Edited by Darien
Posted (edited)
On 2/16/2022 at 12:50 AM, Darien said:

I want to capture the out of the process to know the result of a command DOS. For example:

 

just add :

if $erro <> "" Then MsgBox(64,"",$erro)

if $resultado <> "" Then MsgBox(64,"",$resultado);

below:

$erro = $erro & StderrRead($pid)

 

`

   If $funcao <> "" Then Call($funcao)
        $resultado = $resultado & StdoutRead($pid)
        $erro = $erro & StderrRead($pid)
        If @error Then
            StdioClose($pid)
            Return(_OemToStr($resultado & "|" & $erro))
        EndIf

 

 

Edited by ad777

none

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...