Sign up ×
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:

start java -Xmx8192M -Xms8192M -jar minecraftforge-universal-1.6.2-
timeout /t 300
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
have you used sendkeys before ? – Knuckle-Dragger Jan 4 '14 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… 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 '14 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. – Frankie Jan 4 '14 at 1:39
@barlop, W7 has powershell, so it can be done from command line in batch file. see here… – Knuckle-Dragger Jan 4 '14 at 2:05
That is unless using a com-object is cheating. – Knuckle-Dragger Jan 4 '14 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.

  timeout /t 300 /nobreak ^>nul^&echo save-all^&echo stop^&(call )
)|java -Xmx8192M -Xms8192M -jar minecraftforge-universal-1.6.2-
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 '14 at 14:13

Your Answer


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.