Darien Posted February 15, 2022 Posted February 15, 2022 (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? expandcollapse popup#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 February 15, 2022 by Jos Place the script on the topic body.
Developers Jos Posted February 15, 2022 Developers Posted February 15, 2022 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.
Darien Posted February 15, 2022 Author Posted February 15, 2022 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 Jos Posted February 15, 2022 Developers Posted February 15, 2022 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.
argumentum Posted February 15, 2022 Posted February 15, 2022 2 hours ago, Darien said: ... a lot of processing, it hangs ... Do IPC and your main loop will not hang while waiting for the "troublesome" code. I know that I'm not giving great advise but is something that I do ( IPC ), to not have my main loop hang. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ad777 Posted February 15, 2022 Posted February 15, 2022 @Darien no hang you say's: expandcollapse popup#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
Darien Posted February 15, 2022 Author Posted February 15, 2022 (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 February 15, 2022 by Darien
ad777 Posted February 17, 2022 Posted February 17, 2022 (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 February 17, 2022 by ad777 none
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now