views:

402

answers:

4

Hey,

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)

A: 

I didn't get the question properly. I think parameters (%1,...) should be there.

adatapost
A: 

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.

but it doesnt have a commmand-line version :( i dont want that the user have to type those commands in :s
YourComputerHelpZ
The user won't have to type the commands. Autohotkey will do the typing. Read its tutorial.
In particular you need the Send command: http://www.autohotkey.com/docs/commands/Send.htm
A: 

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.

scraimer
i'm looking for number 2 ;)
YourComputerHelpZ
How can i do it in Windows Scripting Host command??
YourComputerHelpZ
I think the name of the function is `SendKeys`, but I can't remember which object you need. Googling for "sendkeys" gets you to http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx - see the examples at the end of that page.
scraimer
um, the problem is, it isnt available on Vista (so also on 7?) and this should be released to the public so...
YourComputerHelpZ
in that case, I'd recommend using Powershell, I guess...
scraimer
A: 

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
Joey