CiaronJohn Posted December 9, 2019 Posted December 9, 2019 (edited) 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 December 9, 2019 by CiaronJohn Incomplete code
Nine Posted December 9, 2019 Posted December 9, 2019 You cannot connect to stdIO of an existing (already running) process. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
CiaronJohn Posted December 9, 2019 Author Posted December 9, 2019 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
Nine Posted December 9, 2019 Posted December 9, 2019 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
CiaronJohn Posted December 10, 2019 Author Posted December 10, 2019 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. where I should be reading this.
junkew Posted December 10, 2019 Posted December 10, 2019 (edited) 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 December 10, 2019 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Nine Posted December 10, 2019 Posted December 10, 2019 Your error message looks like you should set working directory to cygwin folder. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
CiaronJohn Posted December 16, 2019 Author Posted December 16, 2019 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
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