Shinku Posted November 13, 2007 Share Posted November 13, 2007 Hey, it has been a very long time ago that i posted something here lol anyway I am busy with autoit, wanting to try something with command prompt and stuff but the loops are a bit of a uhm ... well not gonna curse in forums anyway hope you guys could help me out with it expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> GUICreate ( "dosprompt" , 334 , 424, -1, -1) $cmd = GUICtrlCreateInput ( "", 40, 10 , 200 , 20) $textorso1 = GUICtrlCreateLabel ("CMD:", 10, 10, 25, 20) $Close = GUICtrlCreateButton ("Close!", 10, 384, 80,20) $Closex = GUICtrlCreateButton ("sendcommand!", 245, 10, 80,20) $Outputbox = GUICtrlCreateEdit ("[incomminginput]", 10, 55, 314, 300,$ES_READONLY+$ES_MULTILINE+$WS_HSCROLL+$WS_VSCROLL+$ES_AUTOVSCROLL) GUISetState(@SW_SHOW) $cmdinfo = Run("cmd", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD) while 1;;<--- locks up here because its while 1 (keeps looping out =x) $line = StdoutRead($cmdinfo) GUIctrlsetdata($Outputbox, GUIctrlread($Outputbox) & @CRLF & $line); WEnd $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Close exitloop Case $msg = $Closex $inputz = GUICtrlRead($cmd) StdinWrite($cmdinfo, $inputz); recall_command(); EndSelect Wend func recall_command() while ProcessExists($cmdinfo);;<--- locked loop (because it watches the status of the process, and since it always keep existing it just locks here) $line = StdoutRead($cmdinfo) GUIctrlsetdata($Outputbox, GUIctrlread($Outputbox) & @CRLF & $line); WEnd EndFunc how do i fix this? as example, if i remove the first loop and send dir it doesnt give the command to the msdoswindow but it just locks up with the default msg what u have when u open cmd so, it doesnt send "dir" (or any command) at all and.. how can i stop it from looping out when there's no "data stream" but a "pause"? (because it just continues looping, the program locks itself up) Link to comment Share on other sites More sharing options...
Valuater Posted November 13, 2007 Share Posted November 13, 2007 Played with it a little... expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> Global $cmdinfo GUICreate("dosprompt", 334, 424, -1, -1) $cmd = GUICtrlCreateInput("", 40, 10, 200, 20) $textorso1 = GUICtrlCreateLabel("CMD:", 10, 10, 25, 20) $Close = GUICtrlCreateButton("Close!", 10, 384, 80, 20) $Clear = GUICtrlCreateButton("Clear", 100, 384, 80, 20) $Closex = GUICtrlCreateButton("sendcommand!", 245, 10, 80, 20) GUICtrlSetState( -1, $GUI_DEFBUTTON) $Outputbox = GUICtrlCreateEdit("[incomminginput]", 10, 55, 314, 300, $ES_READONLY + $ES_MULTILINE + $WS_HSCROLL + $WS_VSCROLL + $ES_AUTOVSCROLL) GUICtrlSetBkColor( -1, "") GUICtrlSetColor( -1, 0xfffafa) GUISetState(@SW_SHOW) recall_command("dir c:\") $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Close ExitLoop Case $msg = $Clear GUICtrlSetData($Outputbox, "[incomminginput]") Case $msg = $Closex $inputz = GUICtrlRead($cmd) recall_command($inputz); EndSelect WEnd Func recall_command($info) $cmdinfo = Run(@ComSpec & " /c " & $info, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD) While 1 $line = StdoutRead($cmdinfo) If @error Then Return GUICtrlSetData($Outputbox, GUICtrlRead($Outputbox) & @CRLF & $line); WEnd EndFunc ;==>recall_command 8) Link to comment Share on other sites More sharing options...
Shinku Posted November 13, 2007 Author Share Posted November 13, 2007 its nice but thats totally not what i am looking for cmd has to run and stay active, thats all what it does actually and then it will list the output onlything i am hitting myself with is the loop it needs to stop after output and when i send a command it needs to run the loop again till the data stream pauses(when there is no actual output) and not that it runs into loop and keeps running in it so my whilestatement needs a fix, i looked up even added If @error Then ExitLoop but it just keep looping because process exists i got 2 while statements: while 1 $line = StdoutRead($cmdinfo) If @error Then ExitLoop GUIctrlsetdata($Outputbox, GUIctrlread($Outputbox) & @CRLF & $line); WEnd here it loops because i have while 1; so there are no checks func recall_command() while ProcessExists($cmdinfo) $line = StdoutRead($cmdinfo) If @error Then ExitLoop GUIctrlsetdata($Outputbox, GUIctrlread($Outputbox) & @CRLF & $line); WEnd EndFunc and here it checks if the process still exists, which always does till i exit it for somehow i need to find out how to let it check while (getting stream) functions wend so when it stops streaming and hunts into pause; it actually has to exit the loop till new command is sent. only figuring out how =x sorry to say to ya Valuator, but what u showed is totally not what i'm looking for cmd has to start and wait, autoit needs to read output and exit the loop when there is darkness till you send a new command i don't know how i can get the total lines that has been read (but then it isn't live anymore if i look for a certain methode) is there any way how to exit the loop when there is no data getting retrieved for a moment at the cmd? Link to comment Share on other sites More sharing options...
rasim Posted November 13, 2007 Share Posted November 13, 2007 (edited) You want this? expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> Opt("TrayIconDebug", 1) GUICreate ( "dosprompt" , 334 , 424, -1, -1) $cmd = GUICtrlCreateInput ( "", 40, 10 , 200 , 20) $textorso1 = GUICtrlCreateLabel ("CMD:", 10, 10, 25, 20) $Close = GUICtrlCreateButton ("Close!", 10, 384, 80,20) $Closex = GUICtrlCreateButton ("sendcommand!", 245, 10, 80,20) $Outputbox = GUICtrlCreateEdit ("[incomminginput]", 10, 55, 314, 300,$ES_READONLY+$ES_MULTILINE+$WS_HSCROLL+$WS_VSCROLL+$ES_AUTOVSCROLL) GUISetState(@SW_SHOW) $cmdinfo = Run("cmd", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD) $line = StdoutRead($cmdinfo) GUIctrlsetdata($Outputbox, GUIctrlread($Outputbox) & @CRLF & $line); $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Close exitloop Case $msg = $Closex $inputz = GUICtrlRead($cmd) $cmdinfo = Run(@ComSpec & " /c " & $inputz, "", @SW_HIDE, 6) recall_command($cmdinfo) EndSelect Wend Func recall_command($cmdinfo) Local $out = '', $ErrOut = '' While 1 $out &= StdoutRead($cmdinfo) If @error Then ExitLoop WEnd While 1 $Errout &= StderrRead($cmdinfo) If @error Then ExitLoop WEnd If Not $out = '' Then GUIctrlsetdata($Outputbox, $out & @CRLF) ElseIf Not $ErrOut = '' Then GUIctrlsetdata($Outputbox, $Errout & @CRLF) EndIf EndFunc Edited November 13, 2007 by rasim Link to comment Share on other sites More sharing options...
Shinku Posted November 13, 2007 Author Share Posted November 13, 2007 (edited) hmm, didn't try but already seen: Case $msg = $Closex $inputz = GUICtrlRead($cmd) $cmdinfo = Run(@ComSpec & " /c " & $inputz, "", @SW_HIDE, 6) recall_command($cmdinfo) EndSelect what if i run ftp =x Edited November 13, 2007 by Shinku Link to comment Share on other sites More sharing options...
Shinku Posted November 13, 2007 Author Share Posted November 13, 2007 just checked out the source rasim, it's not what i'm looking for, sorry. first it's not like "Live" so it's annoying to see that the program locks itself up for a bit, tried with ftp command, and was funny to see that the program just locked up, unable to close. and that ftp.exe generated 90%+ cpu usage. what i'm really looking for is that it starts the cmd then the gui popup and show the status when u send a command that it write to the cmd application it's also for a use with the live streaming stuff, so if u run a application in the cmd that u can use it (i'm talking about simple programs like ftp, hmm.. telnet is a good example also..) just to say that u can use all command lined programs also. (so not talking about the program "edit" or anything like that, just that you can control the box within autoit) i can do it as far like this. but, i have no idea how to make the loop stop continueing when he finished the commands ie: if i enter dir: F:\test>dir De volumenaam van station F is NieuwVolume Het volumenummer is 1CDA-9C8A Map van F:\test 21-12-2006 22:08 <DIR> . 21-12-2006 22:08 <DIR> .. 0 bestand(en) 0 bytes 2 map(pen) 961.630.208 bytes beschikbaar F:\test> (and here it should end the loop because the prompt backed up and theres no other data to be listed) hope you guys understand what i mean once command has been run and theres no other information comming from the stream the while loop has to stop then and the program has to run and wait for next command you give to it. without stopping cmd or such stuff; because of the command "cd" etc. the while loop is the onlything that has to be changed, so that the loop exit when there is no more data to retrieve from the command you received, and i can't figure it out how there should be a possibility for it. *hopes this explaination is bit better and hope someone knows how to fix it* 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