xain Posted December 2, 2009 Share Posted December 2, 2009 (edited) Hi there, I'm new to AutoIT and finding it rather fantastic... I've been busy away all day making a GUI to run various batch files and psexec routines, and all is looking rather good. However....if somebody could assist me with scripting this i'd very much appreciate it and be able to adapt it for many other uses in my GUI. I basically have a single input box which you can enter an IP address into. Then various buttons which take the input of that box, run a batch file and use the IP as a parameter. On most this works well...however, on things such as pinging an IP, the command prompt will open, do it's job and close immediately. I'm using ShellExecute("whatever.bat", $stringforIPaddress) to get the desired effect Is there any way to grab the output which the command window shows and either display it in a window on my GUI or in a separate window?... Sample script to get a ping information back into a GUI display box would be ideal. If not how can I make the DOS box not disappear? Many Thanks in advance PS: I've done a little searching and don't seem to be able to find a similar request. Also ShellExecuteWait(...) Does not make the command prompt wait either. Thank you Edited December 2, 2009 by xain Link to comment Share on other sites More sharing options...
Developers Jos Posted December 2, 2009 Developers Share Posted December 2, 2009 Use Run(@comspec & " /c ....",...) and add the right parameters to capture the IO. see the Helpfile for all details, JOs SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
xain Posted December 2, 2009 Author Share Posted December 2, 2009 Use Run(@comspec & " /c ....",...) and add the right parameters to capture the IO.see the Helpfile for all details,JOsThanks, I have already seen this and had a bash with it...though it doesn't seem to allow me to use parameters with the batch files which they need...such as the IP address on them.examplegetnameof.bat 192.168.1.1where the IP address would be the parameter for the batch file.Run/RunWait allows entry of parameters for it's own purpose but slings up errors if I try to throw the needed onces in for the bat file...this is why i'm trying things with ShellExecute.Could you give an example of the way in which Run( @ComSpec..... is used as perhaps it is my error but the helpfile is vague regarding it's use.Many Thanks again Jos Link to comment Share on other sites More sharing options...
FuryCell Posted December 2, 2009 Share Posted December 2, 2009 Post the bat and i'll see what i can cook up. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
xain Posted December 2, 2009 Author Share Posted December 2, 2009 Post the bat and i'll see what i can cook up. Thank you P5ych0, I'll not trouble you yet...have had another play with run(@ComSpec..etcHave managed to get some output back and bunged into the GUI so i'll keep playing rather than being an impatient n00b.Saying that i'll probably pull my hair out in a short while and post up the .bat anyways soon Your offer is much appreciated though.Thanks Link to comment Share on other sites More sharing options...
xain Posted December 3, 2009 Author Share Posted December 3, 2009 (edited) Ok, back again and still trying to get to grips...please forgive my lack of experience... I've managed to get my command prompt boxes to stay open but i'm now wanting to move on and see if I can't get some output into a box on the GUI. here's what i'm trying to modify looks long but the only bulk is really the bottom part below the ---GO BUTTON---- the foo.bat which is called simply pings an IP address so is just foo.bat ping 192.168.1.1 which i've bunged into the system32 directory for now. ;------------------------------------------------------------------------------ #include <GuiConstantsEx.au3> #include <AVIConstants.au3> #include <TreeViewConstants.au3> #include <process.au3> #include <Constants.au3> ; GUI GuiCreate("The BOX", 400, 500) GuiSetIcon(@SystemDir & "\mstsc.exe", 0) ; MESSAGE TO USER INPUT $MessageText = GUICtrlCreateEdit('', 80, 385, 250, 80) GUICtrlCreateLabel("Message Window", 80,360,300) ; CONTEXT MENU $contextMenu = GuiCtrlCreateContextMenu() GuiCtrlCreateMenuItem("Context Menu", $contextMenu) GuiCtrlCreateMenuItem("", $contextMenu) ;separator GuiCtrlCreateMenuItem("&Properties", $contextMenu) ; BUTTON1 $button1 = GuiCtrlCreateButton("GO", 65, 155, 105, 30) GUISetState() While 1 $msg = GUIGetMsg() Select ;--------------------------------------------------- ;------------------GO BUTTON------------------- ;--------------------------------------------------- Case $msg = $button1 Local $foo = Run(@ComSpec & " /c foo.bat", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line = StdoutRead($foo) If @error Then ExitLoop MsgBox(0, "STDOUT read:", $line) Wend While 1 $line = StderrRead($foo) If @error Then ExitLoop MsgBox(0, "STDERR read:", $line) Wend MsgBox(0, "Debug", "Exiting...") EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop ; WEnd ; GUI MESSAGE LOOP GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd ;--------------------------------------------------------------------- I can't for the life of me get any real sense into the window there....please can someone give me a pointer or two in getting that working if it is at all possible. Many thanks if somebody could assist with this. Regards xain ps: I'm using GUICtrlSetData instead of msgBox but the best I've achieved so far is to get STDOUT:read to pop up in my GUI message window. Edited December 3, 2009 by xain Link to comment Share on other sites More sharing options...
xain Posted December 3, 2009 Author Share Posted December 3, 2009 Anybody got any pointers for this I'm still unable to get the output syntax right..soo close, so annoying. Thank you Link to comment Share on other sites More sharing options...
Developers Jos Posted December 3, 2009 Developers Share Posted December 3, 2009 try: expandcollapse popup;------------------------------------------------------------------------------ #include <GuiConstantsEx.au3> #include <AVIConstants.au3> #include <TreeViewConstants.au3> #include <process.au3> #include <Constants.au3> ; GUI GUICreate("The BOX", 400, 500) GUISetIcon(@SystemDir & "\mstsc.exe", 0) ; MESSAGE TO USER INPUT $MessageText = GUICtrlCreateEdit('', 80, 385, 250, 80) GUICtrlCreateLabel("Message Window", 80, 360, 300) ; CONTEXT MENU $contextMenu = GUICtrlCreateContextMenu() GUICtrlCreateMenuItem("Context Menu", $contextMenu) GUICtrlCreateMenuItem("", $contextMenu) ;separator GUICtrlCreateMenuItem("&Properties", $contextMenu) ; BUTTON1 $button1 = GUICtrlCreateButton("GO", 65, 155, 105, 30) GUISetState() While 1 $msg = GUIGetMsg() Select ;--------------------------------------------------- ;------------------GO BUTTON------------------- ;--------------------------------------------------- Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button1 ConsoleWrite('@@ Debug = ' & @ComSpec & ' /k "' & @SystemDir & '\foo.bat"' & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Local $foo = Run(@ComSpec & ' /c "' & @SystemDir & '\foo.bat"', @SystemDir, Default,$STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line &= StdoutRead($foo) If @error Then ExitLoop WEnd MsgBox(0, "STDOUT read:", $line) While 1 $line &= StderrRead($foo) If @error Then ExitLoop WEnd MsgBox(0, "STDERR read:", $line) EndSelect WEnd ; GUI MESSAGE LOOP GUISetState() SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Xenobiologist Posted December 3, 2009 Share Posted December 3, 2009 Something like this? MsgBox(64, 'Datum', _getDOSOutput('date /t')) Func _getDOSOutput($command) Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4) While 1 $text &= StdoutRead($Pid, False, False) If @error Then ExitLoop Sleep(10) WEnd Return $text EndFunc ;==>_getDOSOutput Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
xain Posted December 3, 2009 Author Share Posted December 3, 2009 (edited) Thank you JOS, it functions much tidier... is it possible to ever get the output to show in a message box like the one present on the GUI, that was my aim but as said i've been using the command GUICtrlSetData to try and push it into the box but am unsure if the syntax would be correct as it seems to just put actual code in to that message box. Thanks again I really appreciate the help in tidying up the functioning on my current experimental stuff. Regards Xain ps: Hold that, i'll have a go adapting Xeno's code...that does look promising and I need to learn Thanks again both of you...extremely helpful thank you Edited December 3, 2009 by xain Link to comment Share on other sites More sharing options...
GEOSoft Posted December 3, 2009 Share Posted December 3, 2009 GUICtrlSetData($someControl, $Line) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted January 7, 2010 Share Posted January 7, 2010 HI All, is it possible to put the output into a Array without writing to a file ? Thanks Best regards, Emiel Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 8, 2010 Share Posted January 8, 2010 what do you mean? What file? What output? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
GEOSoft Posted January 8, 2010 Share Posted January 8, 2010 Use StdOutRead() and then create the array from that with something like StringSplit() or StringRegExp(). George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted January 8, 2010 Share Posted January 8, 2010 @Xenobiologist It's simple to use the $line to write to a file .. and read the file to an array.. @George Thanks i will try Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
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