how do i run a bat file as if it's interactive? - file

I have an issue where if i run a command manually it prompts for the next volume. which is fine, i can use the '< inputfile.txt' to run this through a batch file.
But what happens if the volume in inputfile.txt hasn't yet been created? - I get an error and the programs crashes out.
I cant change the program that prompts unfortunately as its bundled in a .exe.
My theory would be to run the program as if it's interactive with no '< inputfile.txt' and make the calling program wait until the volume is complete before providing the next volume.
i'm running this:
create.bat < cInputFile >> cTempLog
and get
** Cannot find or open file
if i run manually i get:
Please enter next device or file name or type 'quit' to exit:
Any help would be great,
Thanks

You could write a second batch file to pipe the input into create.bat and sleep before each line.
something like this i'd guess:
#echo off
for /f "delims=" %%i in (cInputFile) do sleep 1 && echo %%i
and run it something like:
input.bat | create.bat >> cLogFile

Related

How to make batch file to run exe file which requires some text

I need to run 'a.exe'.
When I start 'a.exe' file, a console pops up, and I should type "go", then the program start.
If i want to make a batch file to run this program, how should i make this.
I tried as below:
///////////
%~d0
cd %~dp0
start a.exe > "go"
pause
///////////
but "go" appears on the batch console, and the "a.exe" program still requires "go" text.
How can i solve this?
Assuming you are coding a windows .bat script, you can execute any file by just passing the file with its path and its argument on the same line a.exe go, so your script would be something like this:
#echo off
c:\path\to\file\a.exe go
PAUSE
I am turning off CMD echo so the output of a.exe is easier to be read.
There is another question here were this is further explained: Create a batch file to run an .exe with an additional parameter.
On the other hand, if you need to call another script, you would need to use the method call
#echo off
call c:\path\to\other\script\script.bat
c:\path\to\file\a.exe go
PAUSE
You can use:
start echo go| a.exe
Just type in
a.exe go
Hope it helped you out.
You can also use it to run files through certain programs
photoshop img.png

How do I send commands to a command line process

I have a Garry's Mod server I want it to autorestart every 12 hours. I can make a script where it executes a command every 12 hours but I dont know how to send the command "quit" to the process "srcds.exe". I saw something like
echo quit |srcds.exe
I tried it but it didnt work. How do I do this using MS-DOS (batch file)?
You are looking for the taskkill command:
taskkill /f /im srcds.exe
And it kill the tasks srcds.exe
If you can edit the program you want to send a command to, you can try inserting this command line into it where you want it to terminate:
if exist (directory)\(triggering file).txt del /Q (directory)\(triggering file).txt & quit
This will scan for the file that the triggering program will create, delete it, and then quit the program. If the file is not present, the program will ignore the line and move on as if the command line wasn't there.
The triggering program can be run whenever you want to terminate the main program. This program should be:
echo.>"(directory)\(triggering file).txt"
exit
Above was the simplest way of doing this. If you want to make it more "idiot proofed" you can add as the first line of the main program:
echo.>"(directory)\(main run file).txt"
This will write a .txt file the same way the triggering program does. This tells the triggering program that the main program is running and it can terminate it. You will also have to change the above IF statement in the main program to read:
if exist (directory)\(triggering file).txt del /Q (directory)\(main run file).txt & del /Q (directory)\(triggering file).txt & quit
Finally, change the triggering program to read:
if not exist (directory)\(main run file).txt quit
echo.>"(directory)\(triggering file).txt"
quit
Just some final notes, wherever I have "(directory)" replace it and the ()'s with an otherwise unused, untouched directory. Wherever you see "(triggering file)" replace it and the ()'s with a filename that is common with all other places you see "(triggering file)". Same goes to "(main run file)" but it must have a different name then "(triggering file)".
I know this might be confusing. Don't be afraid to comment and ask quesions. I will be happy to clarify.

How to control .exe file with .bat file?

Hi I have program Program.exe which have some 3 parameters. And I am trying to control this program via .bat file. I can run this program with parameters without any problems, its easy. But if this program starts succesfully, then there are two choices what to do. For example if user type 'a' then this program writes on console 'hi'. If user types 'b' then program writes to console 'hello'. I want to somehow sent to this Program.exe only the 'a' choice after start. Unfortunaly I cant add another parameter. Does anyone know how to do it?
So here is my very simple .bat file.
Program %1 %2 %3
and I tried to add this command to .bat file but it doesnt works.
echo a > Program
Thanks for help.
Try:
Echo a| Program %1 %2 %3
That is a known method for most CLI apps, but is not valid for all applications, if the pipe don't work for your app then forget to do it using native Batch and try a nircmd sendkey command or another CLI app to send keys.
Pipes: http://ss64.com/nt/syntax-redirection.html
NirCMD: http://www.nirsoft.net/utils/nircmd.html

Batch File Ending Prematurely

I have a batch file with the following commands (to set up a compiler):
del Yylex.java
jflex scanner.flex
del parser.java
java -jar java-cup-11a.jar parser.cup
However, for some reason, after the conclusion of jflex scanner.flex, the batch script ends and command prompt closes. If I just run that command separately, this does not happen. Does anyone know what's wrong?
Is jflex a batch file?
If so, try
CALL jflex ...
or
start /wait "" jflex ...
(well, actually - give it a whirl anyway, can't hurt...)
When bat is asked to run another batch, it merely transfers control to that other batch and has no idea of where to return. CALL or START gives it a ticket home...

Batch file that doesnt run

I have creted a batch file that I want to run the SetupCodeGroup.exe
When I double click the batch file it doesnt run the exe file. A command prompt opens up but it doesnt run the file. Can someone tell what I missed or what I am missing
C:\Users\raw008\Desktop\Critcare\SetupCodeGroup.exe
type pause on the next line and check whether this executable comes on the command prompt .
try
start C:\Users\raw008\Desktop\Critcare\SetupCodeGroup‌​.exe
moreover
start /d "path_to_file_directory" program.exe
is the complete line to execute program and console will not wait to program to exit .
I wonder if this exe requires administrative privileges. Try right-clicking the batch file and running it as administrator.
#echo off
start C:\Users\raw008\Desktop\Critcare\SetupCodeGroup‌.exe
echo Done
pause
try that if that dose not work then your computers privleges are messed up, i ran into the same problem on my cousins computer.

Resources