Jump to content

Recommended Posts

Posted

I've been searching the board for a while but I haven't come up with anything. Here's my question, can you redirect the output of the function ConsoleWrite() to an Edit box or something else like a log? I know there's _GUICtrlEdit_AppendText but can you redirect ConsoleWrite?

Prove, and I will believe...
Posted

Thats a good question and while I don't have the answer it should be possible to read the output from ConsoleWrite with StdoutRead.

The only other suggestion I can give is to change your ConsoleWrites to FileWriteLine.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

  • 2 weeks later...
Posted

Thats a good question and while I don't have the answer it should be possible to read the output from ConsoleWrite with StdoutRead.

The only other suggestion I can give is to change your ConsoleWrites to FileWriteLine.

I have done something similar where basically, I am storing a Console command into $ConsoleCLI, run it, and dump the output to an edit box. Not sure if this is what you are looking for, but here is the code snippet that makes it happen:

$Output = GUICtrlCreateEdit("", 8, 304, 449, 257, BitOR($ES_AUTOVSCROLL, $ES_NOHIDESEL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))

$PID = Run(@ComSpec & " /c " & $ConsoleCLI, $InstalledDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

    While 1
        $line = StdoutRead($PID)
        If @error Then ExitLoop
        GUICtrlSetData($Output, $line, 1)
    WEnd

    While 1
        $line = StderrRead($PID)
        If @error Then ExitLoop
        GUICtrlSetData($Output, $line, 1)
    WEnd

Hope this helps....

  • 3 months later...
Posted

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

$Form1 = GUICreate("Form1", 633, 454, 193, 125)
$Input1 = GUICtrlCreateInput("Input1", 40, 16, 385, 21)
$Button1 = GUICtrlCreateButton("Execute", 448, 16, 105, 25, 0)
$Output = GUICtrlCreateEdit("", 48, 56, 433, 369, BitOR($ES_AUTOVSCROLL, $ES_NOHIDESEL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)

$InstalledDir=@SystemDir


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            CLI()
    EndSwitch
WEnd

Func CLI()
    $ConsoleCLI=GUICtrlRead($Input1)
    $PID = Run(@ComSpec & " /c " & $ConsoleCLI, $InstalledDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWaitClose($pid)
    $line = StdoutRead($PID)
    GUICtrlSetData($Output, $line, 1)
EndFunc

Normally I'd add a ProcessWaitClose($pid) after the Run() command so I can ensure the command has finished executing before processing the output. Then I know I can do it in one fell swoop instead of the While loop.

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
×
×
  • Create New...