Jump to content

Recommended Posts

Posted (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....:

oml2ov74.gif

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 by MadaraUchiha

Posted (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 by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

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? 

6barwehx.png

Posted

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

#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.

Posted (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 by MHz
Posted

 

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')

  • Solution
Posted

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

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
  • Recently Browsing   0 members

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