karlkar Posted December 24, 2013 Posted December 24, 2013 Hello. I have an application cqtool - it is command line application allowing some operations on ClearQuest database. If you have never met with it, you can treat it as sqlplus, python console or any application launched in console that waits for user commands. I want to make such behaviour that first I run command that logs me in, and then executes new_query command with proper parameters. My code looks so: #include <Constants.au3> Local $iPID = Run(@ComSpec & ' /C cqtool login -s TN_STANDARD -d D01 -u user -p pass', "", @SW_SHOW, $STDIN_CHILD + $STDERR_CHILD + $STDOUT_CHILD) Local $hTimer = TimerInit() ConsoleWrite($iPID & @CRLF) Local $sOutput = "" While 1 Sleep(1000) Local $tmp = StderrRead($iPID) If @error Then ExitLoop ConsoleWrite("read '" & $tmp & "'" & @CRLF) If $tmp == "" Then ContinueLoop ExitLoop WEnd ConsoleWrite('It took ' & TimerDiff($hTimer) / 1000 & ' seconds' & @CRLF) StdinWrite($iPID, 'new_query -eq State Opened -and -eq Owner_List.Owner user -field id -field headline "Personal Queries/query1"') If @error Then ConsoleWrite(@error & @CRLF) Exit EndIf While 1 Sleep(1000) ConsoleWrite("Reading" & @CRLF) Local $tmp = StderrRead($iPID) If @error Then ExitLoop If $tmp <> "" Then ConsoleWrite('Read ' & $tmp & @CRLF) ExitLoop Else ContinueLoop EndIf WEnd Everything to the StdinWrite works fine - cqtool logs in, waits for error message that is shown everytime after logging and then it just stays in second while loop, writing to the console "Reading" all over the time.
spudw2k Posted December 24, 2013 Posted December 24, 2013 What happens if you try using StdOutRead instead of StdErrRead and using $STDIN_CHILD + $STDERR_MERGED instead of $STDIN_CHILD + $STDERR_CHILD + $STDOUT_CHILD That make any difference? Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Gianni Posted December 24, 2013 Posted December 24, 2013 (edited) Hi karlkar (a blind wild guess) what happens with the following modifications? (also: why you read from stderr instead of stout?) #include <Constants.au3> ; Local $iPID = Run(@ComSpec & ' /C cqtool login -s TN_STANDARD -d D01 -u user -p pass', "", @SW_SHOW, $STDIN_CHILD + $STDERR_CHILD + $STDOUT_CHILD) ; <-- Local $iPID = Run(@ComSpec, '', @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) ; <-- Sleep(1000) ; geve time to cmd to born <-- StdinWrite($iPID, 'cqtool login -s TN_STANDARD -d D01 -u user -p pass') ; send the command <-- Local $hTimer = TimerInit() ConsoleWrite($iPID & @CRLF) Local $sOutput = "" While 1 Sleep(1000) Local $tmp = StderrRead($iPID) ; If @error Then ExitLoop If Not @extended Then ExitLoop ; if there is no data to read then exit <-- ConsoleWrite("read '" & $tmp & "'" & @CRLF) ; If $tmp == "" Then ContinueLoop ; ???? <-- ; ExitLoop <-- WEnd ConsoleWrite('It took ' & TimerDiff($hTimer) / 1000 & ' seconds' & @CRLF) StdinWrite($iPID, 'new_query -eq State Opened -and -eq Owner_List.Owner user -field id -field headline "Personal Queries/query1"') If @error Then ConsoleWrite(@error & @CRLF) Exit EndIf While 1 Sleep(1000) ConsoleWrite("Reading" & @CRLF) Local $tmp = StderrRead($iPID) ; If @error Then ExitLoop ; <-- If $tmp <> "" Then ConsoleWrite('Read ' & $tmp & @CRLF) ExitLoop ; Else ; <-- ; ContinueLoop ; <-- EndIf WEnd Edited December 24, 2013 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
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