Jump to content

Recommended Posts

Hi,

I would like to read the output of my cygwin terminal if it is already up and running.

I searched the forum, but I think, the samples were cmd/cygwin needs to be re-run or not yet running.

The purpose of the script is to check if compiling is done.

 

Func _JAE_Rebuild_Software ($sSoftwarePath)

    Local $iMinty = 0

    ; Open cygwin process and check one instance only
    if ProcessExists("mintty.exe") Then
        $iMinty = ProcessExists("mintty.exe")
    Else
        ; Run cygwin if not yet running
        $iMinty = Run("C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -", "", @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD)
    endif

    ; Loop to check if cygwin terminal is ready
    While 1
        ; if -sh is not error cygwin is still opening
        Local $hWnd = WinGetHandle("-sh")
        If @error Then
            $hWnd = WinGetHandle("~")
        Else
            $hWnd = 0
        EndIf

        ; If true cygwin is ready to be written
        if $hWnd <> '0x00000000' Then
            ExitLoop
        EndIf
    WEnd

    ; Change Directory
    $sSoftwarePath = StringReplace($sSoftwarePath,"\", "/")
    ClipPut($sSoftwarePath)

    Send('cd ' & $sSoftwarePath & "{ENTER}" )

    ; Get New Class after Change Directory
    Local $sNewClass = WinGetTitle("[ACTIVE]")

    ; Sleep for 3 seconds.
    Sleep(3000)

    ; Change software path to access the makeFile
    $sSoftwarePath = StringReplace($sSoftwarePath,"/", "\")

    ; Open Makefile
    Local $hFileOpen = FileOpen($sSoftwarePath & "\makefile", $FO_READ)
    If $hFileOpen = -1 Then
        Return False
    EndIf

    Local $sFileRead = FileReadLine($hFileOpen, 12)
    Local $sSetSource = _StringBetween($sFileRead, "(", ")", $STR_ENDNOTSTART)
    Local $message

    Send('source ' & $sSetSource[0] & '.sh' & "{ENTER}")
    Send('make clean' & "{ENTER}")

    WinActivate($sNewClass, "")

    $hWnd = WinWait($sNewClass,"",1)
    Local $iPID = WinGetProcess($hWnd)

    While $iMinty

        $message &= StderrRead($iPID)

         If @error Then
             MsgBox(0,"","error")
           ExitLoop
         EndIf
     WEnd

   ; I only get blank output here since the while condition produces an error

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

 

EndFunc ;==>_JAE_Rebuild_Software

Edited by CiaronJohn
Incomplete code

Share this post


Link to post
Share on other sites

Thanks @Nine,

So i should always re-run the process?

; Open cygwin process and check one instance only
    if ProcessExists("mintty.exe") Then
        $iMinty = ProcessExists("mintty.exe")
    Else
        ; Run cygwin if not yet running
        $iMinty = Run("C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -", "", @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD)
    endif

Share this post


Link to post
Share on other sites

Kill the process first and rerun it with the appropriate parameters :

    $STDIN_CHILD (0x1) = Provide a handle to the child's STDIN stream
    $STDOUT_CHILD (0x2) = Provide a handle to the child's STDOUT stream
    $STDERR_CHILD (0x4) = Provide a handle to the child's STDERR stream
    $STDERR_MERGED (0x8) = Provides the same handle for STDOUT and STDERR. Implies both $STDOUT_CHILD and $STDERR_CHILD.

 

Share this post


Link to post
Share on other sites

Thanks @Nine,

I edited the code

; Open cygwin process and check one instance only
    if ProcessExists("mintty.exe") Then
        ProcessClose("mintty.exe")
    endif

    $iMinty = Run("C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -", "", @SW_SHOW, 0x8)

  While 1
        $sOutput1 &= StdoutRead($iMinty)
        If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
            ExitLoop
        EndIf
        MsgBox(0, "StdoutRead Read:", $sOutput1)
    WEnd

 

I am now getting only 1 message and infinite loop.

image.png.2c0c2b3aea03f502624b839051b4e61c.png

 

where I should be reading this.

image.png.a0365091e48bdb9676fb16d5348e5894.png

Share this post


Link to post
Share on other sites

Alternative is to check for certain log files exist or do not exist or check dates size of certain files to know if compile process is finished.

I assume your compiler can redirect to a file which you just can monitor from AutoIt.

Your make file could write a message to a new file at end of process.

You could send ctrl a and ctrl c with clipget to see if certain text is there.

 

Edited by junkew

Share this post


Link to post
Share on other sites

Thanks for all your help, I just made an output file for the process and created function to check its size

This solved my problem. :)

Func _JAE_Check_OutPutFile($sOutputFile)
    Local    $iRetOutputFile, _
                $iFileSize

    $iRetOutputFile = 0
    While (1)
        ; Sleep for 2 seconds
        Sleep(2000)
        $iFileSize = FileGetSize($sOutputFile)
        ; FileSize will be >0 if done writing
        If $iFileSize > 0 Then
            $iRetOutputFile = 1
            ExitLoop
        EndIf
    WEnd
    Return $iRetOutputFile
EndFunc        ; ==>_JAE_Check_OutPutFile

Share this post


Link to post
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

  • Similar Content

    • By Ganesh2VL
      Dear All, Good Day
      I have created an Autoit script which runs perfectly on local machine,but when i call the same script from a remote machine it failed (window in disable mode, every time when i click manually the screen the script will work). Even i tried mouseclick but failed, please advise. 
       
      Note: My ultimate aim is to automate the task using a automation scheduler which installed on a separate system.
      Please check my below script
      Run("C:\Program Files (x86)\ITProgararm\prgm.exe")
      Send("{ALTDOWN}{ESC}{ALTUP}")
      WinWaitActive("Log into Database Server")
      Send("username{TAB}password{ENTER}")
      WinWaitActive("Error","")
      Send("{ENTER}")
      WinWaitActive("ITProgararm - Program Monitor","")
      Send("{CTRLDOWN}f{CTRLUP}")
      MouseClick("left",135,944,1)
      WinWaitActive("ITProgararm - Program Monitor - [Authorizers]","")
      MouseClick("left",40,109,2)
      WinWaitActive("ITProgararm - Program Monitor - [Authorizer VASA Information]","")
      MouseClick("left",176,95,1)
      MouseClick("left",87,941,1)
      MouseClick("left",1266,8,1)
       
       
      Thanks in advance
       
      VL.Ganesh
    • By tremolux66
      Before I dive into the specifics of my problem, are there known, fatal issues when running a compiled AutoIt script (.exe file) from a Cygwin Bash script? Am I wasting my time trying to get it to work?
      If not, then here's my problem: I have 2 compiled AU3 scripts that are normally executed in the background by a Windows service. The Start script is executed by the service with a directory path as a command-line argument, does some processing, and creates a database record. After an external (human) activity finishes, the Stop script is executed, does some more processing, and updates the database record for the directory. The Bash script emulates the service for purposes of re-processing directories that had errors during the "live" pass: it loops through a text file containing a list of failed directories and executes the Start and Stop scripts.
      If the AU3 script executions are commented-out (e.g., to test other logic in the loop), the Bash script reads through the entire directory-list file; the Start and Stop scripts are treated as if they had run successfully. But if the AU3 scripts are actually executed, the loop exits after the first full iteration (i.e., without skips caused by error-detection).
      Subsequent runs of the Bash script process one directory each and exit (the list file shrinks with each pass). It seems like something about the execution of the AU3 scripts is changing the Bash loop execution (e.g., causing it to see end-of-file for the directory list file). A puzzling aspect is that an earlier version of the Bash script executed successfully (all directories processed), but in that case the directory list was taken from a Bash array variable rather than a file. Since there could be hundreds (or more) directories requiring re-processing, I modified the Bash script to read from a file, with the intention of making it more robust.
      Any suggestions for troubleshooting this will be welcome.
      Outline of the script; the actual script is much longer:
      #!/bin/bash # Initialize variables... export START_EXEPATH="C:/mydir/StartScript.exe" export STOP_EXEPATH="C:/mydir/StopScript.exe" # Generate (unix) text file containing (unix) directory paths, one per line find C:/somedir -type d [some other criteria...] -print >/tmp/dir_list.out # Core code: let errcnt=0 while IFS='' read -r dpath do # Validate the last component of dpath... dpath_base="$(basename "$dpath")" regexp="some-extended-regexp" if [[ "$dpath_base" =~ $regexp ]]; then dpath_bad=0; else dpath_bad=1; fi if [ $dpath_bad -eq 1 ]; then let errcnt+=1; echo "error message"; continue; fi win_dpath="$(cygpath -a -w "$dpath")" # Run 1st AutoIt script "$START_EXEPATH" "$win_dpath" "another-argument" if [ $? -ne 0 ]; then let errcnt+=1; echo "error message"; continue; fi # Run 2nd AutoIt script "$STOP_EXEPATH" "$win_dpath" if [ $? -ne 0 ]; then let errcnt+=1; echo "error message"; fi done </tmp/dir_list.out echo "$errcnt errors" if [ $errcnt -ne 0 ]; then exit 2; fi exit 0  
    • By Joep86
      Hi, 
      I just started recently with AutoIT and I am trying to make two dropdownlists where the selectable values of the second dropdownlist will be depending on what is selected on the first one.
      For example: 
      Dropdown 1                 Dropdown 2                   
      xxx                =>             01-15    ("01" , "02" ,"03" , ...)                    
      yyy                =>             a - f       ("a" , "b" ,"c" ,"d" ,"e" ,"f" ) 
      zzz                =>             "new", "old", "spare"
       
      I started with this code that I've found in this Forum:
      #include <GUIConstantsEx.au3>
      ; Here is the array
      Global $aArray[6] = ["SORT", "PCM", "UNIF", "KKE", "GMS", "CDY"]
      ; And here we get the elements into a list
      $sList = ""
      For $i = 0 To UBound($aArray) - 1
          $sList &= "|" & $aArray[$i]
      Next
      ; Create a GUI
      #include <GUIConstantsEx.au3>
      $hGUI = GUICreate("DropDown", 500, 500)
      ; Create the combo
      $hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
      ; And fill it
      GUICtrlSetData($hCombo, $sList)
      GUISetState()
      While 1
          Switch GUIGetMsg()
              Case $GUI_EVENT_CLOSE
                  Exit
          EndSwitch
       WEnd
       
       
      Any idea how to start on this one...
      thanks upfront
       
       
       
    • By jguinch
      Hi all !

      I work on a tool for automating logon in a business software. This software is a Linux application, displayed in Windows with an EXPORT DISPLAY method, using a X-SERVER (Cygwin/Xterm).
      The problem is when I use Send or ControlSend, special keys like @ or # (or some other keys needing an AltGr combination), the characters sent are the non-AltGr keys (# become 3, @ become 3 - I use a French keyboard).
      I tried to send keys to the Linux-Firefox (instead of the business software), but I had the same result.
      Does anyone has already try to make something like this, with the same issue ?
      Thanks for help
       
    • By Command3r
      Hello, is there anyway to make a gui with autoit and put it in another programming language??

      I want make a program with visual basic but in the same time i want to get some functions and GUIs from autoit.

      All helps and ideas are appreciated.
×
×
  • Create New...