Batch script that runs a command and enters "yes" and "password"

Hey guys, I need to automate a command that connects to a linux folder with authentication. When the command is executed, it asks to continue the connection and "yes" must be entered, a second later the "password" itself must be entered.
I've never done batch scripting or any of  the kind, so maybe some kind of Pause function must be enabled for it to wait a second or two for the two popups (yes and pwd).
Thank You!
Pavlin Penevthe IT guyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you want to pass a "yes" to a script, you can use:

echo yes | myexefilename.exe

This works for passing in a single parameter. To pass in 2 parameters, you can try an input text file with the two parameters, each on it own line.

myexefilename.exe < input.txt

Look at this sample commandline application
        static void Main(string[] args)

            Console.Write("FirstName: ");
            string FirstName = Console.ReadLine();
            Console.Write("LastName: ");
            string LastName = Console.ReadLine();
            Console.Write("Age: ");
            string Age = Console.ReadLine();

            Console.WriteLine("Hi {0} {1}. You are still {2}.", FirstName, LastName, Age);


Open in new window

This takes in 3 parameters.

Using ECHO with a single parameter:
Input: echo Bill | ConsoleApplication1.exe
Output: Hi Bill  . You are still .

If you create a text file as attached (input.txt) which has 3 lines in it and run:
Input: ConsoleApplication1.exe < input.txt
Output: Hi Bill Gates. You are still 15.
Also look at this script (from I haven't tried the pure PowerShell approach though. My approach just relies on how we know batchfiles to work.

# list of expected questions and answers to those questions
$promptResponses = @{
    'Are you sure you want to continue (y/n)? ' = 'y'
    'Enter student name    : ' = 'Ajith'
    'Enter student age     : ' = '22'
    'Enter student sex     : ' = 'M'
    'Enter student Address : ' = '#34, some street, some city'
    'Enter student course  : ' = 'CS'

$process = New-Object System.Diagnostics.Process
$process.StartInfo.FileName = 'cscript.exe'
$process.StartInfo.Arguments = "/nologo commit.vbs"
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.RedirectStandardInput = $true
$process.StartInfo.RedirectStandardOutput = $true
$process.StartInfo.WorkingDirectory = (Get-Location).Path

$process.Start() | Out-Null

# read prompts from program's standard output
# write responses to program's standard input
$promptStream = $process.StandardOutput
$responseStream = $process.StandardInput

# monitor the output of the program until the program ends
while (-not $process.HasExited) {
    # read all outputs from program line by line
    # if the output is a prompt, get response and send a response to program
    do {
        $output = $promptStream.ReadLine()
        if ($output -eq $null) {

        $isPrompt = $promptResponses.ContainsKey($output)
        if ($isPrompt) {
            $response = $promptResponses[$output]
        # send program output and responses to pipeline for display/logging/etc
        Write-Output $output
        if ($isPrompt) {
            Write-Output $response
    } while ($output -ne $null) 


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.