Search code examples
javaexceptioncommand-linecommandautoit

Autoit - Read Java Exception from console


I want to be able to output the result of a commandline input to a AutotIT GUI, which I already managed to do. This command contains a java call.

Unfortunately I am not able to bring possible Java exceptions, like:

10:20:10,313 INFO - Initiate connection from 0.0.0.0/0.0.0.0:0 to 122.168.11.129:2900

storescu: Connection timed out: connect java.net.ConnectException: Connection timed ol.connect0(Native Method)

from the console of my SciTE window to my GUI. I already tried everything google gave me regarding the consoleRead() function, this does not seem to work.

This is part of my code :

Func SendData()
    local $value    = GUICtrlRead($targets)
    local $target   = StringRegExpReplace($value,".*\(","")
    $target         = StringRegExpReplace($target,"\).*","")
    local $trsyntax = StringTrimLeft($value, StringInStr($value,"="))
    local $dcm4che  = GUICtrlRead($dcm4cheGUI)
    local $path     = GUICtrlRead($pathGUI)

    $command = "java -cp .\etc\storescu\;.\etc\certs;.\lib\* org.dcm4che3.tool.storescu.StoreSCU -c " & $target & " " & $path
    $cmd     = Run($command, $dcm4che,@SW_HIDE, 2)

    While True
        $sTMP = StdoutRead($cmd, False, False)
        If @error Then
            ExitLoop 1
        ElseIf $sTMP Then
            $sSTD &= $sTMP
            GUICtrlSetData($eOutput, $sTMP, 1)
        EndIf
        Sleep(100)
    WEnd
EndFunc

The GUICtrlSetData outputs everything into a huge, non-editable Edit field, GUI Config:

GUICreate("SCU Testing Utility", 750, 750, (@DesktopWidth-750)/2, (@DesktopHeight-750)/2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS, $WS_EX_ACCEPTFILES)
GUICtrlCreateLabel("Sending Target: ", 25, 13, 100, 25)
$targets = GUICtrlCreateCombo("", 125, 10, 600, 30)

GUICtrlCreateLabel("dcm4che Path: ", 25, 46, 100, 25)
$dcm4cheGUI = GUICtrlCreateInput("C:\dcm4che-5.10.5", 125, 40, 600, 25)

GUICtrlCreateLabel("File/Folder to send: ", 25, 81, 100, 25)
$pathGUI = GUICtrlCreateInput("", 125, 75, 600, 25)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)

GUICtrlCreateLabel("Set Path: ", 25, 110, 100, 25)

$filebutton   = GUICtrlCreateButton("File", 125, 105, 300, 25)
$folderbutton = GUICtrlCreateButton("Folder", 425, 105, 300, 25)
$eOutput      = GuiCtrlCreateEdit("", 0, 135, 750, 585, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))

$close = GUICtrlCreateButton("Close", 0, 720, 375, 30)
$send  = GUICtrlCreateButton("Send", 375, 720, 375, 30)

Solution

  • Ok I got it, I had to raise the flag from 2 to

    $STDERR_MERGED (0x8) = Provides the same handle for STDOUT and STDERR. Implies both $STDOUT_CHILD and $STDERR_CHILD.