Sign in to follow this  
Followers 0
narayanjr

Cmd.exe read

4 posts in this topic

How would i read text from a cmd window? I need to get the ip address of a game that im in and using netstat -n works but i want to get it out of the console and write it to a notepad

WinGetText returns a blank string and i dont understand the ConsoleRead() function

Thanks

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

that works fine but now i have a new problem

#include <Constants.au3>

$pid = Run(@ComSpec & " /c " & 'netstat -n', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$pos = StringInStr(StdoutRead($pid,9000), ":4000")
$periodpos = StringInStr(StdoutRead($pid,9000), ".",0,78)

WinWaitActive("Untitled")
Send($pos)
Send("{ENTER}")
Send($periodpos)
While 1
    $line = StdoutRead($pid)
    If @error Then ExitLoop
   Send($line)
WendoÝ÷ Ù«­¢+ØÀÌØíÁ½ÌôMÑÉ¥¹%¹MÑÈ¡MѽÕÑI ÀÌØíÁ¥°äÀÀÀ¤°ÅÕ½ÐìèÐÀÀÀÅÕ½Ðì¤(ÀÌØíÁÉ¥½Á½ÌôMÑÉ¥¹%¹MÑÈ¡MѽÕÑI ÀÌØíÁ¥°äÀÀÀ¤°ÅÕ½Ðì¸ÅÕ½Ðì°À°Üà¤oÝ÷ Û^+¬zØb²+kzÛ«Í4ªê-ªê-jëh×6$pos = StringInStr(StdoutRead($pid,9000,true), ":4000")
$periodpos = StringInStr(StdoutRead($pid,9000,true), ".",0,78)

what am i doing wrong?

Edited by narayanjr

Share this post


Link to post
Share on other sites

that works fine but now i have a new problem

what am i doing wrong?

The StdOutRead() runs microseconds after the Run(), and there isn't anything there yet. You need a loop to catch all the output before you start to process it:

#include <Constants.au3>
$Output = ""
$pid = Run(@ComSpec & " /c " & 'netstat -n', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Do
     $Output &= StdoutRead($pid)
Until @error

MsgBox(64, "netstat -n", $Output)

:whistle:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  
Followers 0