Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
1  
have you used sendkeys before ? –  Knuckle-Dragger Jan 4 at 1:17
    
@Knuckle-Dragger sendkeys in what? he is asking about batch. this superuser question asks about sendkeys in batch but the answers involve sendkeys in vbscript stackoverflow.com/questions/16454124/… So what do you mean when you say sendkeys. I remember in win9X there was a sendkeys 3rd party but i'ven ever seen it since. Have you run into something that works in windows 7? –  barlop Jan 4 at 1:39
    
I can't answer your question however you should probably use arguments here for modded servers. Also, giving java more than 4GB ram is bad because it's bad at handeling it. –  Chipperyman Jan 4 at 1:39
    
@barlop, W7 has powershell, so it can be done from command line in batch file. see here superuser.com/questions/696467/… –  Knuckle-Dragger Jan 4 at 2:05
    
That is unless using a com-object is cheating. –  Knuckle-Dragger Jan 4 at 2:12

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
@kelik - Did the pipe work? or did you use AutoIT? –  dbenham Jan 4 at 14:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.