Sign in to follow this  
Followers 0
LoWang

get text from a console (cmd) window

10 posts in this topic

Hello, I am quite sure this has been discussed here a hundred times already, but search function really sucks here :-\

I want to simply get a text from a console app (OpenTTD dedicated server in this case) and do some things around it. Thanks for help

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello, I am quite sure this has been discussed here a hundred times already, but search function really sucks here :-\

I want to simply get a text from a console app (OpenTTD dedicated server in this case) and do some things around it. Thanks for help

The search function here is one of the best I've seen. Maybe you just don't know how to search for anything properly?

Found with sucky search feature

Edit:

And to get really specific:

http://www.autoitscript.com/forum/index.ph...st&p=527810

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

but search function really sucks here :-\

Wow,great conclusion... ever tried reading?:)

anywho.... Autoit already has the function needed to read a console aplication...

from the autoIt Help (that's why they made that stuf,again the reading heh xD)

; Demonstrates the use of StdinWrite()
#include <Constants.au3>

Local $foo = Run("sort.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
; Write string to be sorted to child sort.exe's STDIN
StdinWrite($foo, "rat" & @CRLF & "cat" & @CRLF & "bat" & @CRLF)
; Calling with no 2nd arg closes stream
StdinWrite($foo)

; Read from child's STDOUT and show
Local $data
While True
    $data &= StdoutRead($foo)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "Debug", $data)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for help, but may I ask you how did you get these search results? :P Logically when I tried to find something like this I simply wrote

console read text

of course it found topic "fantastic free software", jokes and many other big topics which are always found no matter what you search for... So I have read advanced usage help and learn that I need to use + sign to search for all the words I type - this is IMHO really stupid, because there is nothing. Why would I type words I don't want to search for

so I search for +console +read +text and find 5 pages of posts with subjects not really looking related.

OK when I check search titles only it is better, but sometimes I am not sure what words to use so I would rather search full posts. In that case I really don't understand why the ones with searched words in subjects are not first in the results... OK so I tried to search for "read text from a console", but I cannot, because "a" is shorter then 3 characters :) It's non sense to measure word length between quotes.

Many times it finds posts simply not containing the words I typed. Why is the first post in the results if it does not contain "text", when I search for +console +read +text and check "Show results as posts" for example?

Edited by LoWang

Share this post


Link to post
Share on other sites

Thanks for help, but may I ask you how did you get these search results? :P Logically when I tried to find something like this I simply wrote

console read text

of course it found topic "fantastic free software", jokes and many other big topics which are always found no matter what you search for... So I have read advanced usage help and learn that I need to use + sign to search for all the words I type - this is IMHO really stupid, because there is nothing. Why would I type words I don't want to search for

so I search for +console +read +text and find 5 pages of posts with subjects not really looking related.

OK when I check search titles only it is better, but sometimes I am not sure what words to use so I would rather search full posts. In that case I really don't understand why the ones with searched words in subjects are not first in the results... OK so I tried to search for "read text from a console", but I cannot, because "a" is shorter then 3 characters :) It's non sense to measure word length between quotes.

Many times it finds posts simply not containing the words I typed. Why is the first post in the results if it does not contain "text", when I search for +console +read +text and check "Show results as posts" for example?

Well, you have to either surround your query by quotes (so that it gives you the exact search) or do as I did: +Read+Console, then I checked the forums I wanted to search, then I checked the radio button that says Search titles only.

This is why titles are so important, when you're descriptive enough in a title, it makes others peoples hunts for answers so much more fluid.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Xantioss I really was reading AutoIt help functions list and also UDF, but did not find anything like it, only ConsoleRead which is different. I found it by search, but can you tell me where is it in the help tree?

I tried to use this function but it does not work...

$pid=run("c:\h\openttd\openttd.exe -D")
winwait("OpenTTD Dedicated Server")
While True
   $data &= StdoutRead($pid)
  ;if $data<>"" then _DebugOut($data)
    _DebugOut($data)
   If @error Then ExitLoop
   Sleep(25)
WEnd

this continuously spams line breaks but not the text the application displays. You can change it to

$pid=run("cmd.exe")

winwait("C:\WINDOWS\system32\cmd.exe")

but it does the same...

Unfortunatelly I did not find anything usefull in the other topics you provided. I will try to look further...

Edited by LoWang

Share this post


Link to post
Share on other sites

You might search the OpenTTD forum at http://forums.openttd.org/ and see if they have anything to say about logging/administrating the server process. Beware, though; their forum has the same sucky search syntax.

There's also the small possibility that the server's output is on STDERR, and so you'd use StderrRead instead...


Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

$pid=run("c:\h\openttd\openttd.exe -D")
winwait("OpenTTD Dedicated Server")
While True
   $data &= StdoutRead($pid)
 ;if $data<>"" then _DebugOut($data)
    _DebugOut($data)
   If @error Then ExitLoop
   Sleep(25)
WEnd
Not saying this will fix everything, but you missed a key piece of code there.

From the help for StdoutRead:

During the call to Run for the child process you wish to read from the STD I/O parameter must have included the value of $STDOUT_CHILD (2) for this function to work properly (see the Run function).

And if you look at the example there you'll see this:

Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I asked on www.tt-forums.net, this is nice forums. That link you wrote does not seem to work.

I somehow got it to work thanks, but that last parameter in run() had to be 7 and I had to use StdErrRead! It works nicely and displays the loading messages via _debugout func, but I still fail to send some command into it and see a response. It does not do anything. I just used these commands when it detected the last message meaning loading is complete:

StdinWrite($pid,"help")

StdinWrite($pid,@CRLF)

StdinWrite($pid)

which should have made it to display some help, but no stderr was read after this so I am not sure it sent the command properly. How can I check this? Is there a possibility to read stderr or stdout and have it in the original console window at once? Or can I somehow make stdin via typing keys into the console window while reading the output via script?...hm now that I think about it, I could maybe do it by using the value 4 in standard_i/o_flag to handle only stderr right?

Edited by LoWang

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