Jump to content

read dos


Recommended Posts

Yes...

#include <Constants.au3>
; Example Usage
$result= _CMDreturn('net stop "Print Spooler"')
msgbox(0,"Version",$result)

;Another Example Usage
$result= _CMDreturn('net start "Print Spooler"')
msgbox(0,"Version",$result)

Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string
    $cmdreturn = ""
    $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)
    While 1 ; loop through the return from the command until there is no more
        $line = StdoutRead($stream)
        If @error Then ExitLoop
        $cmdreturn &= $line
    WEnd
    Return $cmdreturn
EndFunc   ;==>_CMDreturn

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

That script does not work that way. I do not think it is possible to read from a pre-existing DOS window.. unless you are looking at some kind of OCR method.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

  • 5 weeks later...

That script does not work that way. I do not think it is possible to read from a pre-existing DOS window.. unless you are looking at some kind of OCR method.

That's exactly what I'm trying to do -- read from a pre-existing DOS window that is spawned by a windows app. I can get its process id, and I can send text to the dos window via the send command once I activate the window. However, this dos popup window does some processing of its own before asking user to input data, and I need to somehow determine when it's ready for input. Any help would definitely be appreciated!

Thanks,

Danny

Link to comment
Share on other sites

Perhaps this helps:

MsgBox(0+262144, "", "click OK to start a sample CMD window")
$cmd = "ipconfig"
Run(@ComSpec & " /k " & $cmd, "", @SW_SHOW)
MsgBox(0+262144, "", "click OK to read the window to clipbox and show result")
WinWaitActive("[CLASS:ConsoleWindowClass]")
Send("!{space}{down 6}{right}{down 3}{enter 2}")
MsgBox(0+262144, "", ClipGet())

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Perhaps this helps:

MsgBox(0+262144, "", "click OK to start a sample CMD window")
$cmd = "ipconfig"
Run(@ComSpec & " /k " & $cmd, "", @SW_SHOW)
MsgBox(0+262144, "", "click OK to read the window to clipbox and show result")
WinWaitActive("[CLASS:ConsoleWindowClass]")
Send("!{space}{down 6}{right}{down 3}{enter 2}")
MsgBox(0+262144, "", ClipGet())
Yes, this is helpful. After searching through the forums, someone suggested the ALT+SPACE > E > S > {Enter} method of capturing the text to the clipboard, which I believe is what you're illustrating above. Thank you for the quick response!
Link to comment
Share on other sites

Yes, this is helpful. After searching through the forums, someone suggested the ALT+SPACE > E > S > {Enter} method of capturing the text to the clipboard, which I believe is what you're illustrating above. Thank you for the quick response!

ALT+SPACE > E > S > {Enter} works fine on english locale, but other languages have other letters.

For Germany it would be B(earbeiten) + A(lles markieren)

My method is language independant, :D

And even works in Windows 7. :o

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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