Jump to content

Recommended Posts

Posted

i want to read the output of ping command but the thing is that while running the gui if i do

#include <Constants.au3>

Global $DOS, $Message

$DOS = Run(@ComSpec & " /c Ping www.google.com", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $Message = StdoutRead($DOS, True)
    if @error then exitloop
WEnd

MsgBox(0, "Stdout Read:", $Message)

then the gui hangs and you cannot close the window or cancel it...

neither does it receive the click done while reading..

plz help....

  • Developers
Posted

i want to read the output of ping command but the thing is that while running the gui if i do

#include <Constants.au3>

Global $DOS, $Message

$DOS = Run(@ComSpec & " /c Ping www.google.com", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $Message = StdoutRead($DOS, True)
    if @error then exitloop
WEnd

MsgBox(0, "Stdout Read:", $Message)

then the gui hangs and you cannot close the window or cancel it...

neither does it receive the click done while reading..

plz help....

don't see a GUI in your code so what about you post something we can work of and understand what you are trying?

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

He did it to. It just got stuck in the while..whent loop.

#include <Constants.au3>

Global $DOS, $Message = '' ;; added "= ''" for show only.

$DOS = Run(@ComSpec & " /c Ping www.google.com", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
 Sleep(10) ;; no need to go at full speed here.
 $Message &= StdoutRead($DOS) ;; ditched peek parameter + changed "=" to "&=" ... No more endless loop.
 if @error then exitloop
WEnd

MsgBox(0, "Stdout Read:", $Message)

Why use a loop at all?

#include <Constants.au3>

Global $DOS, $Message = '' ;; added "= ''" for show only.

$DOS = Run(@ComSpec & " /c Ping www.google.com", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($DOS)
$Message = StdoutRead($DOS)

MsgBox(0, "Stdout Read:", $Message)
Posted (edited)

Don't know about OP plans. Multi pinging comes to mind.

That's fine, but unless you need access to the information in real-time there's no need for a loop of that nature. If you are doing multiple pings you may need to loop through and wait for all processes to close:

Global Const $PING_COUNT = 10
Local $aPids[$PING_COUNT], $aResults[$PING_COUNT]

For $i = 0 To UBound($aPids) - 1
    $aPids[$i] = Run()
Next

For $i = 0 To UBound($aPids) - 1
    ProcessWaitClose($aPids[$i])
    $aResults[$i] = StdoutRead($aPids[$i])
Next

Those loops serve an entirely different (and necessary) purpose, however.

Edited by Valik
Minor mistake.
Posted (edited)

i used ping as an example the actual program is a youtube downloader which i have got as a script .py so i am just making a gui for it

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Global $q , $_url , $_url , $_name , $tmp ,$tmp1 ,$tmp2 ,$tmp3 ,$temp ,$foo ,$ex
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("YouTube Downloader         GUI by me", 324, 250, 302, 218)
$Download = GUICtrlCreateButton("Download", 96, 208, 75, 25, $WS_GROUP)
$exit = GUICtrlCreateButton("Cancel", 192, 208, 75, 25, $WS_GROUP)
$url = GUICtrlCreateInput("", 72, 24, 225, 21)
GUICtrlCreateLabel("Url :-", 24, 24, 40, 22)
GUICtrlSetFont(-1, 12, 800, 0, "Lucida Sans")
GUICtrlCreateGroup("OutPut", 16, 56, 281, 57)
GUICtrlSetFont(-1, 9, 400, 0, "Lucida Sans")
$out = GUICtrlCreateInput("", 96, 72, 121, 23, $WS_DISABLED)
GUICtrlCreateLabel("OutFile :-", 24, 80, 65, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans")
$brow = GUICtrlCreateButton("Browse", 224, 72, 65, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$qual = GUICtrlCreateCheckbox("Best Quality", 24, 152, 105, 33)
GUICtrlSetFont(-1, 9, 400, 0, "Lucida Sans")
$name = GUICtrlCreateInput("", 136, 120, 153, 25)
GUICtrlCreateLabel("Name Of Video", 24, 128, 101, 20)
GUICtrlSetFont(-1, 9, 800, 0, "Lucida Sans")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _ProcessCloseEx($foo)
            Exit
        Case $exit
            $ex= 1
            _ProcessCloseEx($foo)
            Exit
        Case $brow
            $temp = FileSelectFolder("Select Output Folder","",2,"",$Form1)
            GUICtrlSetData($out,$temp)
        Case $qual
            $temp = GUICtrlRead($qual)
            If $temp = $GUI_UNCHECKED Then
                $q = ""
                Else
                $q = "-b"
            EndIf
        Case $Download
            $tmp2 = GUICtrlRead($out)
            $tmp1 = GUICtrlRead($url)
            If $tmp1 = "" Then
                MsgBox(16,"Error","No URL Entered")
            Else
                $_url = $tmp1
            EndIf
            $tmp3 = ""
            $tmp3 = GUICtrlRead($name)
            If $tmp3 = "" Then
                MsgBox(16,"Error","Enter Video Name")
            ElseIf $tmp2 = "" Then
                    MsgBox(16,"Error","Specify OutPut Folder")
                Else
                    $_out = $tmp2
                    $_name = $tmp3
            $cmd = "download.py -o "& '"'& $_out & "\ "& $_name &'"' & " "& $q & " "& $_url
            MsgBox(0,"",$cmd)
            Global $foo = Run(@ComSpec &" /c "& $cmd, @DesktopDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
            Local $line
                Do
                $line = StdoutRead($foo)
                ConsoleWrite($line)
            Until @error Or $ex =1
            _ProcessCloseEx($foo)
            EndIf

    EndSwitch
WEnd

Func _ProcessCloseEx($sPID)
    If IsString($sPID) Then $sPID = ProcessExists($sPID)
    If Not $sPID Then Return SetError(1, 0, 0)

    Return Run(@ComSpec & " /c taskkill /F /PID " & $sPID & " /T", @SystemDir, @SW_HIDE)
EndFunc

and the processcloseex it just a attempt i tried to make but it does not work

the gui hangs and does not respond until the download has finished.

i also want to give it a progress bar and cancel button

the console output is like

[download] Reading Web page
[download] 01.00% 2002/39049kb  --.-kb/s
Edited by akshay
Posted

Rather obvious logic flaw. Of course the GUI hangs when you prevent the GUI message loop from reaching the top when you block it with another loop. Particularly when the other loop is poorly written and results in an infinite loop. Anyway, moving this to support.

Posted

Rather obvious logic flaw. Of course the GUI hangs when you prevent the GUI message loop from reaching the top when you block it with another loop. Particularly when the other loop is poorly written and results in an infinite loop.

so what should i do plz edit the code according to you...
Posted

If thats your goal your going to need to adjust(ditch) the loop valik is talking about.

Or, and in my view a better solution, switch to the alternative GUI mode that AutoIt has ... To learn more about that start with the GUI Event Modes

i edited it but still didnt work

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Opt("GUIOnEventMode",1)
Global $q , $_url , $_url , $_name , $tmp ,$tmp1 ,$tmp2 ,$tmp3 ,$temp ,$foo ,$ex
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("YouTube-DL         GUI by -=| akx |=-", 324, 250, 302, 218)
$Download = GUICtrlCreateButton("Download", 96, 208, 75, 25, $WS_GROUP)
$exit = GUICtrlCreateButton("Cancel", 192, 208, 75, 25, $WS_GROUP)
$url = GUICtrlCreateInput("", 72, 24, 225, 21)
GUICtrlCreateLabel("Url :-", 24, 24, 40, 22)
GUICtrlSetFont(-1, 12, 800, 0, "Lucida Sans")
GUICtrlCreateGroup("OutPut", 16, 56, 281, 57)
GUICtrlSetFont(-1, 9, 400, 0, "Lucida Sans")
$out = GUICtrlCreateInput("", 96, 72, 121, 23, $WS_DISABLED)
GUICtrlCreateLabel("OutFile :-", 24, 80, 65, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Lucida Sans")
$brow = GUICtrlCreateButton("Browse", 224, 72, 65, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$qual = GUICtrlCreateCheckbox("Best Quality", 24, 152, 105, 33)
GUICtrlSetFont(-1, 9, 400, 0, "Lucida Sans")
$name = GUICtrlCreateInput("", 136, 120, 153, 25)
GUICtrlCreateLabel("Name Of Video", 24, 128, 101, 20)
GUICtrlSetFont(-1, 9, 800, 0, "Lucida Sans")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIctrlSetOnEvent($Download,"_down")
GUICtrlSetOnEvent($GUI_EVENT_CLOSE,"_quit")
GUICtrlSetOnEvent($exit,"_quit")
GUICtrlSetOnEvent($qual,"_chq")
GUICtrlSetOnEvent($brow,"_browse")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _ProcessCloseEx($foo)
            Exit
        Case $exit
            $ex= 1
            _ProcessCloseEx($foo)
            Exit
        Case $brow
            $temp = FileSelectFolder("Select Output Folder","",2,"",$Form1)
            GUICtrlSetData($out,$temp)
        Case $qual
            $temp = GUICtrlRead($qual)
            If $temp = $GUI_UNCHECKED Then
                $q = ""
                Else
                $q = "-b"
            EndIf
        #cs Case $Download
            $tmp2 = GUICtrlRead($out)
            $tmp1 = GUICtrlRead($url)
            If $tmp1 = "" Then
                MsgBox(16,"Error","No URL Entered")
            Else
                $_url = $tmp1
            EndIf
            $tmp3 = ""
            $tmp3 = GUICtrlRead($name)
            If $tmp3 = "" Then
                MsgBox(16,"Error","Enter Video Name")
            ElseIf $tmp2 = "" Then
                    MsgBox(16,"Error","Specify OutPut Folder")
                Else
                    $_out = $tmp2
                    $_name = $tmp3
            $cmd = "download.py -o "& '"'& $_out & "\ "& $_name &'"' & " "& $q & " "& $_url
            MsgBox(0,"",$cmd)
            Global $foo = Run(@ComSpec &" /c "& $cmd, @DesktopDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
            Local $line
                Do
                $line = StdoutRead($foo)
                ConsoleWrite($line)
            Until @error Or $ex =1
            _ProcessCloseEx($foo)
            EndIf
#ce
    EndSwitch
WEnd

Func _ProcessCloseEx($sPID)
    If IsString($sPID) Then $sPID = ProcessExists($sPID)
    If Not $sPID Then Return SetError(1, 0, 0)

    Return Run(@ComSpec & " /c taskkill /F /PID " & $sPID & " /T", @SystemDir, @SW_HIDE)
EndFunc

Func _down()
            $tmp2 = GUICtrlRead($out)
            $tmp1 = GUICtrlRead($url)
            If $tmp1 = "" Then
                MsgBox(16,"Error","No URL Entered")
            Else
                $_url = $tmp1
            EndIf
            $tmp3 = ""
            $tmp3 = GUICtrlRead($name)
            If $tmp3 = "" Then
                MsgBox(16,"Error","Enter Video Name")
            ElseIf $tmp2 = "" Then
                    MsgBox(16,"Error","Specify OutPut Folder")
                Else
                    $_out = $tmp2
                    $_name = $tmp3
            $cmd = "youtube-dl.py -o "& '"'& $_out & "\ "& $_name &'"' & " "& $q & " "& $_url
            MsgBox(0,"",$cmd)
            Global $foo = Run(@ComSpec &" /c "& $cmd, @DesktopDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
            Local $line
                Do
                $line = StdoutRead($foo)
                ConsoleWrite($line)
            Until @error Or $ex =1
            _ProcessCloseEx($foo)
            EndIf

EndFunc

Func _quit()
    _ProcessCloseEx($foo)
    Exit
EndFunc

Func _chq()
    $temp = GUICtrlRead($qual)
            If $temp = $GUI_UNCHECKED Then $q = ""
            If Not $temp = $GUI_UNCHECKED Then  $q ="-b"

            EndFunc

Func _browse()
    $temp = FileSelectFolder("Select Output Folder","",2,"",$Form1)
            GUICtrlSetData($out,$temp)
EndFunc

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