1

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.

9
  • 1
    have you used sendkeys before ? Commented Jan 4, 2014 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
    Commented Jan 4, 2014 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.
    – Jon
    Commented Jan 4, 2014 at 1:39
  • @barlop, W7 has powershell, so it can be done from command line in batch file. see here superuser.com/questions/696467/… Commented Jan 4, 2014 at 2:05
  • That is unless using a com-object is cheating. Commented Jan 4, 2014 at 2:12

1 Answer 1

0

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.

1
  • @kelik - Did the pipe work? or did you use AutoIT?
    – dbenham
    Commented Jan 4, 2014 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .