Automatically answer input prompt of an exe started within a windows batch - windows

I have an InputPromptAutomation.exe that prompts for a user input when started and closes if the user input is s:
C:\>AutomateInputPrompt\InputPromptAutomation.exe
Input 's' to stop the application:
s
C:\>
My Problem: I want to automate the startup of the .exe, such that I can start it by double-clicking a StartInputPrompt.bat. How can I automatically pass the s input, such that InputPromptAutomation.exe starts AND exits upon executing StartInputPrompt.bat?

echo s | AutomateInputPrompt\InputPromptAutomation.exe
Here's an example of piping Dir into a new CMD instance
Echo dir | cmd /k
Put S then Enter in a file.
AutomateInputPrompt\InputPromptAutomation.exe < file.txt
Here's an example of doing a dir then a Type c:\windows\win.ini
File.txt (remember to press enter after the last line). This IS NOT a batch file (even though it is identical to one because I'm use CMD as a sample program).
dir
type c:\windows\win.ini
Then type
cmd /k < file.txt
This assumes the program is reading from StdIn, as most, but not all console programs do. EG when you see Press any key to continue the program is NOT reading stdin.
Start is an internal command name. Do not name batch files start as it will cause problems under some circumstances.

Related

Why is an error message output instead of starting an executable in subdirectory of batch file directory?

An error message is output when I try to start "launcher.exe" located in anylocation\ffa\ with this command:
start \ffa\launcher.exe
Batch script should have access to file because stored on disk like this:
ANYLOCATION/myprogram.bat
ANYLOCATION/ffa/launcher.exe
If I type
start /ffa/launcher.exe
output is: invalid switch
But if I type
start \ffa\launcher.exe
output is system cannot find file
Which mistake to I made on starting launcher.exe?
%~dp0
is your batch file directory. So
%~dp0\ffa\launcher.exe
There is no need to use start.
Starting a Program
See start /? and call /? for help on all three ways.
Specify a program name
c:\windows\notepad.exe
In a batch file the batch will wait for the program to exit. When
typed the command prompt does not wait for graphical
programs to exit.
If the program is a batch file control is transferred and the rest of the calling batch file is not executed.
Use Start command
start "" c:\windows\notepad.exe
Start starts a program and does not wait. Console programs start in a new window. Using the /b switch forces console programs into the same window, which negates the main purpose of Start.
Start uses the Windows graphical shell - same as typing in WinKey + R (Run dialog). Try
start shell:cache
Use Call command
Call is used to start batch files and wait for them to exit and continue the current batch file.

Make System information Batch file

How to create a batch file about system info and ip address and domain server etc. _ which will generate a output as txt file
You can put whatever Windows commands you want in a batch file and then redirect the output to a text file using >. E.g., you could create a batch file called test.bat and put the following commands in it:
#echo off
systeminfo
ipconfig /all
Then you could run test.bat from a command prompt as follows:
C:>test >outfile.txt
The output of the batch file, which would consist of the output from the commands you placed in it, would be redirected to a file named outfile.txt by the redirect operator, >. Note: it can sometimes take awhile for the output of the systeminfo command to complete, so, depending on your system, you may need to give it a minute to complete.
Alternatively, you could add the >outfile.txt at the end of commands within the batch file itself, though for every instance after the first one you need to use double greater than signs, i.e., >>, to append the output rather than wiping out what was in outfile.txt previously and creating a new version of that text file. E.g., you could have the following in test.bat:
#echo off
systeminfo >outfile.txt
ipconfig /all >>outfile.txt
You would then just use the following at a command prompt:
C:>test

how to write a cmd command to move file and close console in one statement

Can i write a cmd command which moves file in Windows and later closes the console in one statement?
Consider my following question for full description of the scenario:
how to write a regedit key's value to move a file without opening console
This batch file will close after moving the file, assuming the target folder exists.
#move "c:\folder\file.txt" "c:\newfolder\"
move file1 file2 & exit
If you want to close the command line only if the move command was successful, use double ampersand:
move file1 file2 && exit
You can also create a batch file and run it instead of running cmd. The console window will close automatically (the exit command is not necessary)

Run an input file using an exe file with cmd

I am using Windows 7
How can i run an input file (text file of commands) in an exe progam in CMD please.
Using other questions on the site, i have tried:
CMD /c ""C:/Program Files/Mplus/Mpluswin.exe" "C:/Users/jj/Desktop/mplus/test_mplus.inp""
which opens the input file in the program but does not run it
and this, which opens the program, but not the script
CMD /c "C:/Program Files/Mplus/Mpluswin.exe" < "C:/Users/jj/Desktop/mplus/test_mplus.inp"
Does this depend on the exe program?
Edit:
At present, the first command above launches the exe program and opens the text file within it (this is a file of program specific commands that will read in data, run calculations and output automatically). I can then run the commands in the exe program that has been opened (by selecting run in a menu) . But, I would like to pass the file to the exe program and it to be run automatically, ideally in the background. I am not sure of the correct terminology to use, so sorry if my description is unclear.
I've just noticed that you enclosed the entire term in an extra set of double quotes, and used linux forward slashes - try this batch file and also see if there is any error message on the console.
#echo off
cd /d "%userprofile%\Desktop\mplus"
"C:\Program Files\Mplus\Mpluswin.exe" "test_mplus.inp"
echo mplus was launched
pause

Background processes in batch with redirected output

I'm trying to run several background processes from a batch file and have the output directed to a file. Is it possible to do this in Windows? This is what I've tried but it end up directing the output of the start program rather then background process.
start myapp.exe > myapp.out 2>&1
Actually it is quite easy without using a helper batch file. You just need to run the application via cmd.exe instead, and make sure to escape the special characters so they pass through to cmd.exe.
You probably don't want to see an extra console window, so use the START /B option.
start /b "" cmd /c myapp.exe ^>myapp.out 2^>^&1
Each STARTed process must have its output directed to a unique file. Multiple processes cannot share the same output file.
I think the only chance you have is to create one batch file for each exe that you want to start. Inside the batch file you can redirect the output. The master batch file would then "start" the batch file, not the exe directly.
You just need to include an exit command at the end of each batch file:
start_myapp.cmd contains the following:
myapp.exe > myapp.out 2>&1
exit
then you can run
start start_myapp.cmd
and the output will be redirected

Resources