Deniz Zoeteman
Deniz Zoeteman

Reputation: 10121

Send commands to other command-line programs

Is there a way, to send commands to another command-line program?

'Cause i have a special command-line program, but I can't send commands to it using syntax like program.exe something_to_do

the program executes something like this: ("here syntax" is where i want to input text to and also enter to start)

TheWhateverCommandLineProgram
Version 1.1
Give an option: "here syntax"

the program in code looks something like this:

echo TheWhateverCommandLineProgram
echo Version 1.1
Set opt=
set /p opt=Give an option: 
if %opt%==command1 goto com1
if %opt%==command2 goto com2
...

Well, i guess so cause it wasnt me who made it (btw: off course its not called TheWhateverCommandLineProgram)

Upvotes: 5

Views: 21713

Answers (3)

Joey
Joey

Reputation: 354794

If you just want to give keyboard input to a commandline program you can just use echo and pipe it:

echo some text | program.exe

If you need more lines, then write them to a file and use input redirection:

echo one line > file
echo second line >> file
program.exe < file

Upvotes: 7

Shalom Craimer
Shalom Craimer

Reputation: 21459

I'm not 100% sure I understand what you're looking for. Here's two options:

  1. You have two windows, each running a batch program. Let's say they are called myscript1.bat and myscript2.bat. You want to send a set of commands from myscript1.bat to be executed by myscript2.bat

  2. You have a single batch script named myscript.bat, which executes a single program named program.exe. You want program.exe to execute some commands, or do some something.

Are either of these what you're looking for? Here's some idea:

  1. Make myscript1.bat create a third file, mycommands.bat. Once myscript2.bat sees the file mycommands.bat exists, it will execute it and delete it. (Wow. Lame.)

  2. Use Windows Scripting Host command (it's built in to Windows since Win2K) or Powershell (usually on most computers nowadays, if they have been updated). Either of these can send keystrokes to another program. Using those keystrokes, you can control the other program.

Upvotes: 1

User
User

Reputation:

In what form does the other program take input? From the command prompt?

If the latter then I recommend Autohotkey: http://www.autohotkey.com/

You can use Autohotkey as a bridge and it will send the command as keypresses to the window of the other batch file.

You can ask for help in their forum. They are quite helpful.

Upvotes: 0

Related Questions