Search code examples
batch-filehttp-redirectcmd

Insert echo command into running command line


I have .exe file that opens up a command window and waits for user input, let's call it program.exe.

I would like to automatically insert the user input into that running Program.

For example if I write a batch file using this, I would like to start the program and insert the command entered by the user into the command line of the started program.

@echo off
call program.exe
echo command1

This would start the program and "simulate" the input of command1 into the command line of the opened program.

How can I achieve this?


Solution

  • I would use powershell to start the application and pass the command:

    $psi = New-Object System.Diagnostics.ProcessStartInfo
    $psi.FileName = "proogram.exe"
    $psi.UseShellExecute = $false
    $psi.RedirectStandardInput = $true
    $p = [System.Diagnostics.Process]::Start($psi)
    Start-Sleep -s 2 #wait 2 seconds so that the process can be up
    $p.StandardInput.WriteLine("command1")