Jump to content

Redirect DOS output to an Edit Box?


gamingmouse
 Share

Recommended Posts

I have a GUI that contains a button to start a cmd line java program. That program, in turn, writes output to stdout as it runs. I know that I can use:

RunWait(@COMSPEC & " java myapp.MyExe")

to start the program. But I would like to redirect the programs output to an Edit box inside my AutoIt GUI. Furthermore, I want to be able to stop the program from running by clicking a "Stop" button on my GUI.

Is this possible?

Thanks for any help,

gm

Link to comment
Share on other sites

  • 2 weeks later...

I am trying what is listed above and some ideas from the help file but I am getting error when running the script. I have posted my code below and the error I am getting is Error: Variable used without being declared. I don't know how to attache pictures or I would give you what I see but it looks like it doesn't like the $line variable?

#NoTrayIcon
#include <GUIConstants.au3>
GUICreate ("Telnet")
GUISetIcon (@windowsdir & "\system32\telnet.exe",0)
GUISetState (@SW_SHOW)
$coreA = GUICtrlCreateRadio ("Core Router A",10,10,100)
$coreB = GUICtrlCreateRadio ("Core Router B",10,30,100)
$balanced = GUICtrlCreateRadio ("Load Balanced Address",10,50,150)
GUICtrlSetState ($balanced,$GUI_CHECKED)
$connectbutton = GUICtrlCreateButton ("Connect",20,80,90)
$cancelbutton = GUICtrlCreateButton ("Cancel",200,360,100)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Then
        ExitLoop
    EndIf
    if $msg = $connectbutton And BitAND (guictrlread ($coreA),$GUI_CHECKED) = $GUI_CHECKED Then
        $line = Run(@ComSpec & "/c dir",@workingdir,@sw_hide,$STDOUT_CHILD)
        $read = StdoutRead ($line)
        msgbox (0,"",$read)
    EndIf
    
    
    
    
    
WEnd
Link to comment
Share on other sites

#NoTrayIcon
#include <GUIConstants.au3>
Global $Line
GUICreate ("Telnet")
GUISetIcon (@windowsdir & "\system32\telnet.exe",0)
GUISetState (@SW_SHOW)
$coreA = GUICtrlCreateRadio ("Core Router A",10,10,100)
$coreB = GUICtrlCreateRadio ("Core Router B",10,30,100)
$balanced = GUICtrlCreateRadio ("Load Balanced Address",10,50,150)
GUICtrlSetState ($balanced,$GUI_CHECKED)
$connectbutton = GUICtrlCreateButton ("Connect",20,80,90)
$cancelbutton = GUICtrlCreateButton ("Cancel",200,360,100)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Then
        ExitLoop
    EndIf
    if $msg = $connectbutton And BitAND (guictrlread ($coreA),$GUI_CHECKED) = $GUI_CHECKED Then
        $line = Run(@ComSpec & "/c dir",@workingdir,@sw_hide,$STDOUT_CHILD)
        $read = StdoutRead ($line)
        msgbox (0,"",$read)
    EndIf
   
   
   
   
   
WEnd

Edited by D-Generation X
Link to comment
Share on other sites

Try this:

#NoTrayIcon
#include <Constants.au3>
#include <GUIConstants.au3>
GUICreate ("Telnet")
GUISetIcon (@windowsdir & "\system32\telnet.exe",0)
GUISetState (@SW_SHOW)
$coreA = GUICtrlCreateRadio ("Core Router A",10,10,100)
$coreB = GUICtrlCreateRadio ("Core Router B",10,30,100)
$balanced = GUICtrlCreateRadio ("Load Balanced Address",10,50,150)
GUICtrlSetState ($balanced,$GUI_CHECKED)
$connectbutton = GUICtrlCreateButton ("Connect",20,80,90)
$cancelbutton = GUICtrlCreateButton ("Cancel",200,360,100)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Then
        ExitLoop
    EndIf
    if $msg = $connectbutton And BitAND (guictrlread ($coreA),$GUI_CHECKED) = $GUI_CHECKED Then
        $line = Run(@ComSpec & " /c dir",@workingdir,@sw_hide,$STDOUT_CHILD)
        $read = StdoutRead ($line)
        msgbox (0,"",$read)
    EndIf
WEnd

Errors:

#include <Constants.au3>

$line = Run(@ComSpec & " /c dir",@workingdir,@sw_hide,$STDOUT_CHILD)

--> missing space before /c

Also look at HelpFile at example for StdoutRead :P

Link to comment
Share on other sites

I took the advice of both Zedna and D-Generation X but I am still getting the "Variable used without being declared" error. Below is the new code that I have and I will type out the error message as I see it. As a side note, how do I add a screen shot to my posts?

#NoTrayIcon
#include <GUIConstants.au3>
Global $line
GUICreate ("Telnet")
GUISetIcon (@windowsdir & "\system32\telnet.exe",0)
GUISetState (@SW_SHOW)
$coreA = GUICtrlCreateRadio ("Core Router A",10,10,100)
$coreB = GUICtrlCreateRadio ("Core Router B",10,30,100)
$balanced = GUICtrlCreateRadio ("Load Balanced Address",10,50,150)
GUICtrlSetState ($balanced,$GUI_CHECKED)
$connectbutton = GUICtrlCreateButton ("Connect",20,80,90)
$cancelbutton = GUICtrlCreateButton ("Cancel",200,360,100)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Then
        ExitLoop
    EndIf
    if $msg = $connectbutton And BitAND (guictrlread ($coreA),$GUI_CHECKED) = $GUI_CHECKED Then
        $line = Run(@ComSpec & " /c" & 'dir',@workingdir,@sw_hide,$STDERR_CHILD + $STDOUT_CHILD)
        $read = StdoutRead ($line)
        msgbox (0,"",$read)
    EndIf
    
WEnd

The error is after I have the first radio button checked and hit the connect button.

"Line 31 (<file name>)

$line = Run(@ComSpec & " /c" & 'dir',@workingdir,@sw_hide,$STDERR_CHILD + $STDOUT_CHILD)

$line = Run(@ComSpec & " /c" & 'dir',@workingdir,@sw_hide,^ERROR

Error: Variable used without being declared"

Note that I added the space after " /c"

I also changed the Run command to reflect the help files example of command, I tried both ways (the old way and this way)

Hope this helps you guys caues it sure doesn't help me out.

Edited by jonez34
Link to comment
Share on other sites

I took the advice of both Zedna and D-Generation X but I am still getting the "Variable used without being declared" error. Below is the new code that I have and I will type out the error message as I see it. As a side note, how do I add a screen shot to my posts?

#NoTrayIcon
#include <GUIConstants.au3>
Global $line
GUICreate ("Telnet")
GUISetIcon (@windowsdir & "\system32\telnet.exe",0)
GUISetState (@SW_SHOW)
$coreA = GUICtrlCreateRadio ("Core Router A",10,10,100)
$coreB = GUICtrlCreateRadio ("Core Router B",10,30,100)
$balanced = GUICtrlCreateRadio ("Load Balanced Address",10,50,150)
GUICtrlSetState ($balanced,$GUI_CHECKED)
$connectbutton = GUICtrlCreateButton ("Connect",20,80,90)
$cancelbutton = GUICtrlCreateButton ("Cancel",200,360,100)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Then
        ExitLoop
    EndIf
    if $msg = $connectbutton And BitAND (guictrlread ($coreA),$GUI_CHECKED) = $GUI_CHECKED Then
        $line = Run(@ComSpec & " /c" & 'dir',@workingdir,@sw_hide,$STDERR_CHILD + $STDOUT_CHILD)
        $read = StdoutRead ($line)
        msgbox (0,"",$read)
    EndIf
    
WEnd

The error is after I have the first radio button checked and hit the connect button.

"Line 31 (<file name>)

$line = Run(@ComSpec & " /c" & 'dir',@workingdir,@sw_hide,$STDERR_CHILD + $STDOUT_CHILD)

$line = Run(@ComSpec & " /c" & 'dir',@workingdir,@sw_hide,^ERROR

Error: Variable used without being declared"

Note that I added the space after " /c"

I also changed the Run command to reflect the help files example of command, I tried both ways (the old way and this way)

Hope this helps you guys caues it sure doesn't help me out.

You need to add the following line to the beginning of your script

#include <Constants.au3>

as Zedna did

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

So, now that I have that working I have hit another road block. The intention of this GUI is to make it easier for the other people in my office to look at the status of the VPN tunnels established in our 2 core cisco routers. Since I would rather them not log into the Cisco's them selves I figure this is good way for them to be able to see only what they need to and nothing else. So with the code I have already I need to some how get the GUI to once the connect button is hit to telnet to the router specified, log in to the router then allow the user to choose 2 options. But before I get to all that I need some way for the GUI to tell me that it has connected to the router first. As an example, I would llike to the GUI to connect to the IP that I will give it and then log in, but if the login fails then I need to know that and not just throw the next command at it when it's not connected. I was thinking of somehow reading the stdoutread for the User Access Verification prompt that you get when you are telneting into something, then have the GUI enter the credentials. From there the user then will have a choice to see high speed or dial-up tunnels which the GUI then passes to the telnet session and then somehow returns the results into the GUI for the user to see. I think that I might be biting off more than I can chew here. I would like to know first off how to read into the Stdoutread to see if a certian string exists then continue on or show the user a message saying the connection failed or something like that. My code so far is posted.

#NoTrayIcon
#include <GUIConstants.au3>
#include <Constants.au3>
GUICreate ("Telnet")
GUISetIcon (@windowsdir & "\system32\telnet.exe",0)
GUISetState (@SW_SHOW)
$coreA = GUICtrlCreateRadio ("Core Router A",10,10,100)
$coreB = GUICtrlCreateRadio ("Core Router B",10,30,100)
$balanced = GUICtrlCreateRadio ("Load Balanced Address",10,50,150)
GUICtrlSetState ($balanced,$GUI_CHECKED)
$connectbutton = GUICtrlCreateButton ("Connect",20,80,90)
$cancelbutton = GUICtrlCreateButton ("Cancel",200,360,100)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Then
        ExitLoop
    EndIf
    if $msg = $connectbutton And BitAND (guictrlread ($coreA),$GUI_CHECKED) = $GUI_CHECKED Then
        $line = Run(@ComSpec & " /c ping helpdesk2",@workingdir,@SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)
        $read = StdoutRead ($line,300)
        ;if $read = GUICtrlRead ($line) And $line = 
    EndIf
    
    
    
    
    
WEnd
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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