Jump to content

Forking functions


Guest s_mack
 Share

Recommended Posts

This may not be an efficient way of doing things, but out of pure curiousity and fascination with AutoIt's TCP functions, it would be possible to use the idea of the script calling itself with a parameter, combined with the TCP functions to pass data and track the secondary processes.

I like this idea, however I would suggest that StdOutRead() and StdInWrite() ConsoleWrite() (and maybe StdInWrite() and ConsoleRead()) probably offer a more failsafe way of doing things (TCP/IP may not be installed or a software firewall may hinder even loopback activity). Edited by LxP
Link to comment
Share on other sites

I'm with Alex; it would require moving _CheckStatus to a child script that communicated back to the GUI script with ConsoleWrite via StdoutRead in the parent GUI script. Not knowing anything about _CheckStatus I don't know if it would be more appropriate to re-run the child script every time you wanted an update or to have the child script be looping itself and kill it with ProcessClose when the GUI exits.

Old example script that demonstrates the concept of GUI + StdoutRead:

; Script generated by AutoBuilder 0.5 Prototype

#include <GuiConstants.au3>

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("GUI + StdoutRead", 425, 322,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

; Create a read-only edit control
$eOutput = GuiCtrlCreateEdit("", 0, 10, 423, 260, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
; Exit button
$bExit = GuiCtrlCreateButton("Exit", 340, 285, 60, 20)

GuiSetState()
; Run child process and provide console i/o for it.
; Parameter of 2 = provide standard output 
$ourProcess = Run("ping autoitscript.com", @SystemDir, @SW_HIDE, 2)
; Loop and update the edit control unitl we hit EOF (and get an error)
While 1
   If $ourProcess Then
      ; Initially test to see if characters are waiting
      $charsWaiting = StdoutRead($ourProcess, 0 , 1)
      If @error = -1 Then
         $ourProcess = 0
         MsgBox(0, "App Exited", "Process has exited...")
         ContinueLoop
      EndIf
      ; Don't try to read unless characters are waiting; we don't want to block in a GUI loop...
      If $charsWaiting Then
         $currentRead = StdoutRead($ourProcess)
         GUICtrlSetData($eOutput, $currentRead, 1)
      EndIf
   EndIf
   $msg = GuiGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $bExit
         ExitLoop
      Case Else
        ;;;
   EndSelect
WEnd
Exit

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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