Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 690
Deniz Zoeteman Avatar asked Jul 29 '09 08:07

Deniz Zoeteman


People also ask

How do you go to other files in cmd?

If the folder you want to open in Command Prompt is on your desktop or already open in File Explorer, you can quickly change to that directory. Type cd followed by a space, drag and drop the folder into the window, and then press Enter. The directory you switched to will be reflected in the command line.

Can you use cmd to program?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.

Can you run two command prompts?

Click Start, type cmd, and press Enter to open a command prompt window. In the Windows taskbar, right-click the command prompt window icon and select Command Prompt. A second command prompt window is opened.


2 Answers

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
like image 69
Joey Avatar answered Sep 23 '22 18:09

Joey


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.

like image 33
Shalom Craimer Avatar answered Sep 25 '22 18:09

Shalom Craimer