Jump to content

Recommended Posts

Posted

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.

Posted

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?

Posted (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 by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

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