0

I am running a batch file which runs a battle in Robocode from within java, and then collecting the results of the battle. The code I am using to run the batch file is:

Process p = Runtime.getRuntime().exec("cmd /c C:\\Users\\Joel\\Documents\\ver5Files\\battle.bat");
p.waitFor();

The contents of my batch file are:

cd "C:\robocode"
java -DNOSECURITY=true -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar robocode.Robocode -nodisplay -battle battles\DT_battle.battle -results resultsv5.txt
exit

This works fine if I run a battle with less than 35 rounds in robocode, however when I try and run one with 35 or more battles the code hangs and never returns to the java code.

I investigated further by running modifying the batch file so that it ran with a display, so I could watch the battles and find out where it was hanging. Once the 35th battle is done, it enters the "Round 35 cleaning up" step, and basically gets hung up there. The program isnt frozen or anything, it just wont initialize the next battle.

I have discussed it with someone who is working on a similar project and they are not having these issues, nor does our code differ significantly for this part. I have tried running it on two different machines, but get the same result on both.

Any advice?

Pottsiex5
  • 487
  • 2
  • 6
  • 19

1 Answers1

1

Try to use /k instead of /c and tell me if it works.

Well, if you look at cmd.exe commands you will see it has many options. Some of them are:

/C     Run Command and then terminate

/K     Run Command and then return to the CMD prompt.
          This is useful for testing, to examine variables

You may find more options here.

gabriel garcia
  • 368
  • 3
  • 17
  • Its a engine where you program tanks to fight against each other: http://robocode.sourceforge.net/ In this case I am running the fights from my code and then collecting the results of them from a file afterwards. – Pottsiex5 Feb 27 '16 at 00:10
  • `I am running a batch file which runs a battle in Robocode from within java, and then collecting the results of the battle.` I don't really think it's a nice idea to write Java and batch in the same line haha. What about doing the entire code in Java? You can write the outputs in a file... – gabriel garcia Feb 27 '16 at 00:17
  • Robocode is a separate piece of software. My batch file runs robocode (which can be run from the command line). Robocode produces a results file, which I can then read in java. I am running the batch file from within java so I can automate the process. – Pottsiex5 Feb 27 '16 at 00:25
  • I just downloaded Robocode. Can you show me your batch? – gabriel garcia Feb 27 '16 at 00:27
  • The batch file is in my original post. The flags set are turning off some security so my tank can read and write to files, turning off the gui so it will run the simulation faster, and passing it a battle file which contains the parameters for the battle. – Pottsiex5 Feb 27 '16 at 00:34
  • My bad... looks like its time to go to bed for me hahaha – gabriel garcia Feb 27 '16 at 00:37
  • Mmmm.... do you know how much memory is your program using from the ram memory? (I'm talking about this: -Xmx512M) – gabriel garcia Feb 27 '16 at 00:58