Jump to content

Read text from dos prompt?


Recommended Posts

Hey all, I'm working on making an automated installer for the Folding at Home project, but I'm running into some problems.

For some lame reason, the installer is set up in a way that you have to type in the configuration settings, there is no way to set it up with command line switches or a config file. Frustrating, but Autoit makes it a lot easier.

The problem I am having is that the options for installing change depending on wether or not you have previously installed FAH before. I want it to run as a service, and if I am installing it for the first time then I enter 'yes' to the question, but if it is being reinstalled then I have to enter 'no'. The prompt is different for the question, so if I could read the text from the cmd prompt then I could just use a simple if statement and solve all my problems. How do I read text from the cmd prompt? I've tried using WinGetText and StdoutRead, but both dont return anything. I'm stuck here, any help would be really appreciated!

Link to comment
Share on other sites

I have done some automated things similar to this and piped them into a file and then read the file.

for instance to get the prompt you pipe into a text file

install > test.txt

and then you could read the file and depending on what is in there answer install prompts.

Might be worth a try.

Link to comment
Share on other sites

Something like this to get you started:

#include <Constants.au3>

$Username = "covaks" & @CRLF
$TeamNumber = @CRLF
$Service = "no" & @CRLF
$AskFetch = "no" & @CRLF
$UseIE = "yes" & @CRLF
$BigUnits = "yes" & @CRLF
$AdvancedOptions = "no" & @CRLF

$foo = Run ("c:\temp\FAH504-Console.exe", "c:\temp", @SW_HIDE, $STDIN_CHILD+$STDOUT_CHILD)


While 1
    $line = StdoutRead($foo)
    If @error Then
        msgbox(1,"","Error")
        ExitLoop
    EndIf
    
    msgbox(1,"",$line)
    
    Select
        Case StringInStr($line,"User Name") > 0
            StdinWrite($foo,$Username)
        Case StringInStr($line,"Team Number") > 0
            StdinWrite($foo,$TeamNumber)
        Case StringInStr($line,"service (yes/no)") > 0
            StdinWrite($foo,$Service)
        Case StringInStr($line,"fetching/sending") > 0
            StdinWrite($foo,$AskFetch)
        Case StringInStr($line,"Internet Explorer") > 0
            StdinWrite($foo,$UseIE)
        Case StringInStr($line, "large memory demands") > 0
            StdinWrite($foo,$BigUnits)
        Case StringInStr($line,"advanced options") > 0
            StdinWrite($foo, $AdvancedOptions)
            ExitLoop
    EndSelect
    
WEnd

; This just keeps reading so you can see what happens.  You probably want to fix this up
; Maybe a gui with a read only edit box that updates or something, or however you want
; to display the output once it's running. 
While 1
    $line = StdoutRead($foo,500)
    If @error Then
        msgbox(1,"","Error")
        ExitLoop
    EndIf
    
    msgbox(1,"",$line)
WEnd
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...