MadaraUchiha Posted December 2, 2013 Share Posted December 2, 2013 (edited) Hey, Some of you guys might knwo that I already asked a similar question some time ago here: '?do=embed' frameborder='0' data-embedContent>> The fianl solution was working fine, but I tried to make it a bit more simplistic, just with a InputBox to enter the command, and display the output in a mesagebox. #include <WindowsConstants.au3> #include <Constants.au3> #include <Misc.au3> $DOS = Run('"' & @ComSpec & '"', '', @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) Global $tail $command = InputBox('Enter Command','Please enter a command for the Console') while true StdinWrite($DOS, $command & @CRLF) $tail = '' $Stdout = StdoutRead($DOS) $tail &= $Stdout If StringLen($tail) > 0 Then MsgBox(0, 'tail', $tail) $tail = '' $command = InputBox('Enter Command','Please enter a command for the Console') EndIf WEnd If ProcessClose(@AutoItPID) Then StdInWrite($DOS, 'Exit' & @CRLF) ProcessWaitClose($DOS) EndIf But I have one strange problem... It does not manage the correct command, instead it always gives me the response to the one i entered before....: Instead it should, before the msgbox appears show the copyright and then when I enter a command, display the correct output. Maybe I can make 2 Functions, one to show the copyright and the other to send the commands? ... I am kinda confused... Edited December 2, 2013 by MadaraUchiha Link to comment Share on other sites More sharing options...
Gianni Posted December 2, 2013 Share Posted December 2, 2013 (edited) #include <Constants.au3> $DOS = Run(@ComSpec, '', @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) While ProcessExists($DOS) If StringRight(StdoutRead($DOS, True), 1) = '>' Then MsgBox(0, 'Output is', StdoutRead($DOS)) StdinWrite($DOS, InputBox('Enter Command (exit to quit)', 'Please enter a command for the Console') & @CRLF) EndIf WEnd Edited December 2, 2013 by PincoPanco MadaraUchiha 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 3, 2013 Author Share Posted December 3, 2013 Hey, thats close to perfect. I modified it a bit so it stops when I hit cancel, but there is one last strange thing: #include <Constants.au3> $DOS = Run(@ComSpec, '', @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) While ProcessExists($DOS) If StringRight(StdoutRead($DOS, True), 1) = '>' Then MsgBox(0, 'Output is', StdoutRead($DOS)) $Command = InputBox('Enter Command (exit to quit)', 'Please enter a command for the Console') & @CRLF If not $Command = @error Then StdinWrite($DOS, $Command & @CRLF) Else Exit EndIf EndIf WEnd It echos the path twice? Link to comment Share on other sites More sharing options...
Gianni Posted December 3, 2013 Share Posted December 3, 2013 removed the ending @crlf from line 17 you can quit also by typing exit in the InputBox bye #include <Constants.au3> $DOS = Run(@ComSpec, '', @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) While ProcessExists($DOS) If StringRight(StdoutRead($DOS, True), 1) = '>' Then MsgBox(0, 'Output is', StdoutRead($DOS)) $Command = InputBox('Enter Command (exit to quit)', 'Please enter a command for the Console') & @CRLF If Not $Command = @error Then StdinWrite($DOS, $Command) Else Exit EndIf EndIf WEnd Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 5, 2013 Author Share Posted December 5, 2013 Thanks thats fine, but is there a way to make two different functions of this? one for send command and another one to display the copyright? Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 5, 2013 Author Share Posted December 5, 2013 No ideas?:/ Link to comment Share on other sites More sharing options...
JohnOne Posted December 5, 2013 Share Posted December 5, 2013 #include <Constants.au3> HotKeySet("z", "_Read") HotKeySet("x", "_Write") $DOS = Run(@ComSpec, '', @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) While ProcessExists($DOS) Sleep(10) WEnd Func _Read() ConsoleWrite("Read" &@LF) MsgBox(0, 'Output is', StdoutRead($DOS)) EndFunc ;==>_Read Func _Write() ConsoleWrite("Write" &@LF) $Command = InputBox('Enter Command (exit to quit)', 'Please enter a command for the Console') & @CRLF If Not @error Then StdinWrite($DOS, $Command) Else Exit EndIf EndFunc ;==>_Write AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
MHz Posted December 6, 2013 Share Posted December 6, 2013 (edited) Perhaps using @ComSpec in cmdline mode is easier then using StdInWrite. The code below will get the copywrite banner and the initial prompt which is saved to the $prompt variable. It loops with each command and shows the result in a MsgBox. The $prompt is shown in each MsgBox. #include <Constants.au3> Global $prompt, $stdout ; get the copyright banner and the initial prompt $pid = Run('"' & @ComSpec & '" /c "' & @ComSpec & '"', '', @SW_HIDE, $STDERR_MERGED) Do Sleep(10) $prompt &= StdOutRead($pid) Until @error ; loop with each command run in cmdline mode While 1 $command = InputBox('Enter Command','Please enter a command for the Console') If @error Then ExitLoop $pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, $STDERR_MERGED) Do Sleep(10) $stdout &= StdOutRead($pid) Until @error MsgBox(0, @ComSpec, $prompt & $command & @CRLF & @CRLF & $stdout) $stdout = '' WEnd Edited December 6, 2013 by MHz Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 6, 2013 Author Share Posted December 6, 2013 Perhaps using @ComSpec in cmdline mode is easier then using StdInWrite. The code below will get the copywrite banner and the initial prompt which is saved to the $prompt variable. It loops with each command and shows the result in a MsgBox. The $prompt is shown in each MsgBox. #include <Constants.au3> Global $prompt, $stdout ; get the copyright banner and the initial prompt $pid = Run('"' & @ComSpec & '" /c "' & @ComSpec & '"', '', @SW_HIDE, $STDERR_MERGED) Do Sleep(10) $prompt &= StdOutRead($pid) Until @error ; loop with each command run in cmdline mode While 1 $command = InputBox('Enter Command','Please enter a command for the Console') If @error Then ExitLoop $pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, $STDERR_MERGED) Do Sleep(10) $stdout &= StdOutRead($pid) Until @error MsgBox(0, @ComSpec, $prompt & $command & @CRLF & @CRLF & $stdout) $stdout = '' WEnd Thanks for the reply. thats a good idea to combine them. I tried to make them in a fucntion but it seems that for some reason the command can't be specified in the parameters? Whats wrong with my script: #include <Constants.au3> Global $prompt, $stdout Func RemoteShell($command) ; get the copyright banner and the initial prompt $pid = Run('"' & @ComSpec & '" /c "' & @ComSpec & '"', '', @SW_HIDE, $STDERR_MERGED) Do Sleep(10) $prompt &= StdOutRead($pid) Until @error ; loop with each command run in cmdline mode While 1 If @error Then ExitLoop $pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, $STDERR_MERGED) Do Sleep(10) $stdout &= StdOutRead($pid) Until @error MsgBox(0, @ComSpec, $prompt & $command & @CRLF & @CRLF & $stdout) $stdout = '' WEnd EndFunc RemoteShell('tasklist') Link to comment Share on other sites More sharing options...
Solution MHz Posted December 6, 2013 Solution Share Posted December 6, 2013 Perhaps this is suitable. Not sure if you want an input box in the function as you left it out of your last attempt and it would make a parameter strange to have that you request. ; get the copyright banner and the initial prompt $prompt = RemoteShell('"' & @ComSpec & '"') While 1 $command = InputBox('Enter Command','Please enter a command for the Console') If @error Then ExitLoop MsgBox(0, @ComSpec, $prompt & $command & @CRLF & @CRLF & RemoteShell($command)) WEnd Func RemoteShell($command) ; run command in cmdline mode Local $pid, $stdout Local Const $STDERR_MERGED = 8 $pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, $STDERR_MERGED) Do Sleep(10) $stdout &= StdOutRead($pid) Until @error Return $stdout EndFunc MadaraUchiha 1 Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 6, 2013 Author Share Posted December 6, 2013 Thanks man, problem solved with your help now ^^ 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