themax90 Posted August 3, 2006 Posted August 3, 2006 (edited) This is what I am running (this is just an example): #include <Constants.au3> $foo = Run(@SystemDir & "\cmd.exe", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD) While 1 $line = StdoutRead($foo) If @error = -1 Then ExitLoop MsgBox(0, "STDOUT read:", $line) WEnd While 1 $line = StderrRead($foo) If @error = -1 Then ExitLoop MsgBox(0, "STDERR read:", $line) WEnd MsgBox(0, "Done", "CMD Opened. Sending Help.") StdinWrite($foo, "help" & @LF) StdinWrite($foo) MsgBox(0, "Debug", "Help Sent. Trying to Read.") While 1 $line = StdoutRead($foo) If @error = -1 Then ExitLoop MsgBox(0, "STDOUT read:", $line) WEnd While 1 $line = StderrRead($foo) If @error = -1 Then ExitLoop MsgBox(0, "STDERR read:", $line) WEnd MsgBox(0, "Debug", "Exiting...")oÝ÷ ØéÁzÖµßAèÁëÞ§íz»ayø«²Ô^iا+cºËl¶l"Ëaƺ +ë-jw«®èl©j»@+mç!jxw±jjez;¬´Ä®º+{-y§h|Jë¢ Edited August 3, 2006 by AutoIt Smith
themax90 Posted August 3, 2006 Author Posted August 3, 2006 (edited) Tested on .133 and Still not working. Researching it a bit more. If I send a command to the CMD window, it automatically closes. Here is something I am working on. Send help, or any command and you will find the cmd process closes..... expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> $StdGUI = GUICreate("GUIExample", 492, 431, 200, 125) $StdSend = GUICtrlCreateButton("Send StdIn", 336, 8, 145, 33) $StdRead = GUICtrlCreateInput("", 8, 16, 313, 21, -1, $WS_EX_CLIENTEDGE) GUICtrlSetColor($StdRead, 0xC0C0C0) GUICtrlSetBkColor($StdRead, 0x800000) $StdOut = GUICtrlCreateEdit("", 8, 55, 475, 180, BitOR($ES_READONLY, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE)) GUICtrlSetColor($StdOut, 0xC0C0C0) GUICtrlSetBkColor($StdOut, 0x800000) GUICtrlSetTip($StdOut, "Reads the Stdout of Command Process.") $StdErr = GUICtrlCreateEdit("", 8, 240, 475, 180, BitOR($WS_BORDER, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE)) GUICtrlSetColor($StdErr, 0xC0C0C0) GUICtrlSetBkColor($StdErr, 0x800000) GUICtrlSetTip($StdErr, "Reads the Stderr of Command Process.") $CmdPid = Run(@SystemDir & "\cmd.exe", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD) GUISetBkColor(0x000080, $StdGUI) GUISetState(@SW_SHOW, $StdGUI) While 1 $msg = GUIGetMsg() If Not ProcessExists($CmdPid) Then Exit MsgBox(16, "ERROR", "The Command process is gone!") Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $StdSend SplashTextOn("Updating...", "Sending command and reading...", 300, 30) StdinWrite($CmdPid, GUICtrlRead($StdRead) & @LF) StdinWrite($CmdPid) While 1 $Buffer = StdoutRead($CmdPid) If @error Then ExitLoop GUICtrlSetData($StdOut, GUICtrlRead($StdOut) & @CRLF & $Buffer) WEnd While 1 $Buffer = StderrRead($CmdPid) If @error Then ExitLoop GUICtrlSetData($StdErr, GUICtrlRead($StdErr) & @CRLF & $Buffer) WEnd GUICtrlSetData($StdRead, "") SplashOff() EndSelect WEnd ProcessWaitClose($CmdPid) Exit I really need to know is this abug, or something wanted by Std functions? Edited August 3, 2006 by AutoIt Smith
Skruge Posted August 3, 2006 Posted August 3, 2006 It's not a bug. The output stream isn't closed until the process decides to (usually when it ends), so your while loop never ends. On the same note, you shouldn't close STDIN after each write, as you'll never get it back. I'll dig up my old code so you can have a working example. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]
themax90 Posted August 3, 2006 Author Posted August 3, 2006 (edited) Nevermind, I had not idea the Console functions were related. Thank you. I would love to see your examples. Figured it out... Finally.... expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #Include <GUIEdit.au3> Global $StdGUI = GUICreate("GUIExample", 492, 431, 200, 125) Global $StdSend = GUICtrlCreateButton("Send StdIn", 336, 8, 145, 33) Global $StdRead = GUICtrlCreateInput("", 8, 16, 313, 21, -1, $WS_EX_CLIENTEDGE) GUICtrlSetColor($StdRead, 0xC0C0C0) GUICtrlSetBkColor($StdRead, 0x800000) Global $StdOut = GUICtrlCreateEdit("", 8, 55, 475, 180, BitOR($ES_READONLY, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE)) GUICtrlSetColor($StdOut, 0xC0C0C0) GUICtrlSetBkColor($StdOut, 0x800000) GUICtrlSetTip($StdOut, "Reads the Stdout of Command Process.") Global $StdErr = GUICtrlCreateEdit("", 8, 240, 475, 180, BitOR($WS_BORDER, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE)) GUICtrlSetColor($StdErr, 0xC0C0C0) GUICtrlSetBkColor($StdErr, 0x800000) GUICtrlSetTip($StdErr, "Reads the Stderr of Command Process.") Global $CmdPid = Run(@SystemDir & "\cmd.exe", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD) GUISetBkColor(0x000080, $StdGUI) GUISetState(@SW_SHOW, $StdGUI) AdlibEnable("IOCheck") While 1 $msg = GUIGetMsg() If Not ProcessExists($CmdPid) Then Exit MsgBox(16, "ERROR", "The Command process is gone!") Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $StdSend StdinWrite($CmdPid, GUICtrlRead($StdRead) & Chr(10)) GUICtrlSetData($StdRead, "") EndSelect WEnd ProcessClose($CmdPid) Exit Func IOCheck() $Bytes = StdoutRead($CmdPid, "", True) If $Bytes > 0 Then $Buffer = StdoutRead($CmdPid, $Bytes) GUICtrlSetData($StdOut, GUICtrlRead($StdOut) & @CRLF & $Buffer) EndIf $Bytes = StderrRead($CmdPid, "", True) If $Bytes > 0 Then $Buffer = StderrRead($CmdPid, $Bytes) GUICtrlSetData($StdErr, GUICtrlRead($StdErr) & @CRLF & $Buffer) EndIf _GUICtrlEditLineScroll ($StdOut, Default, _GUICtrlEditGetLineCount ($StdOut)) _GUICtrlEditLineScroll ($StdErr, Default, _GUICtrlEditGetLineCount ($StdErr)) EndFunc ;==>IOCheck Now you can talk to Windows Command....technically dos shell. In a patriotic shell . Edited August 4, 2006 by AutoIt Smith
MHz Posted August 4, 2006 Posted August 4, 2006 A good example script AutoIt Smith. Couple of minor bugs with squares in output, would be incorrect carraige returns perhaps, but overall nice. Would be a good idea to add to Scripts'n'Scraps so it can be shared.
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