Sunday, November 4, 2018

windows 7 - writing a batch file: having a batch insert a command into another cmd-based program


i'm trying to have my batch open another cmd based program, wait some time, then input some commands into the cmd-based program, but can't find any documentation on how to do it. this is the batch file as it is written so far:


:loop
start java -Xmx8192M -Xms8192M -jar minecraftforge-universal-1.6.2-9.10.1.871.jar
timeout /t 300
save-all
stop
timeout /t 120
goto loop

basically, the program runs then after 300 secs its supposed to save then close, then wait 120 secs, then loop. but the batch as it is right now inputs the "save-all" and "stop" commands into itself rather than the running program. i have to use the "start" command to run it in a separate instance or else the batch never runs any of the following commands.


Answer



Perhaps you can pipe the commands into your running program. You want the left part of the pipe to wait before it echos the commands.


:loop
(
timeout /t 300 /nobreak ^>nul^&echo save-all^&echo stop^&(call )
)|java -Xmx8192M -Xms8192M -jar minecraftforge-universal-1.6.2-9.10.1.871.jar
timeout /t 120 /nobreak
goto loop

The (call ) is a fast method to do a no-op. The extra command is needed to prevent a trailing space from being appended to the end of the stop command.


If that does not work, then you definitely can do what you want using AutoIT freeware.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...