1

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?

5
  • maybe echo command1|program.exe. Whether it works or not depends on how exactly the .exe is programmed. Commented Sep 28, 2020 at 12:45
  • Tryed, but this doesn' work. Also I have more then just a single comand that I would like to execute in sequence. I do not need a single batch I would also be fine with just starting the exe and then running a batch that redirect the text into the open cmd window from that exe file. (like a recorded macro) Commented Sep 28, 2020 at 12:55
  • 1
    more than one could be done with (echo command1&echo command2)|program.exe. But when a single input doesn't work, multiple inputs won't work as well. For your second idea, that can't be done with cmd alone. The help of another language, which has some sort of SendKey command is needed (like for example vbs) Commented Sep 28, 2020 at 12:59
  • Okay. I will use autoIT for that purpose. It works. Thanks for input Commented Sep 28, 2020 at 13:26
  • another approach program.exe<command.txt where command.txt holds comand1 or whatever, proved that program exe accepts such input Commented Sep 28, 2020 at 13:54

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

1 Comment

I will try this. This is exactly what I am looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.