Jump to content

Get text in cygwin


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

Link to comment
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.

 

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

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

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

×
×
  • Create New...