0

I'm trying to start another program I've written with the program I'm currently writing. Right now I am trying to do so by starting the batch file I created for it, but that doesn't seem to work, but I don't know why.

Runtime.getRuntime().exec( "cmd F/AKS/Abgaben/Aufgabenblatt1/allesRichtig/runTest1.bat");

Am I doing something wrong with the command? Even though it does seem to find the bat file.

Mike
  • 14,010
  • 29
  • 101
  • 161
Ipomea
  • 121
  • 2
  • 16

1 Answers1

0

Try to use:

Runtime.getRuntime().exec("cmd /c start F:\\AKS\\Abgaben\\Aufgabenblatt1\\allesRichtig\\runTest1.bat");

Additional code snippet:
https://stackoverflow.com/a/7952126/462347

Community
  • 1
  • 1
Mike
  • 14,010
  • 29
  • 101
  • 161
  • If i try that, my cmd opens and says it cant find the file which the batch-file is supposed to start. But if i start the batch file normally through the explorer it works just fine. – Ipomea Feb 04 '16 at 15:13
  • @MaryLu, I'd try to save you bat in the same folder as your Java project and try to execute it in order to assure that there is no issue with the permissions. Also, please, check that any third part software (e.g. antivirus) doesn't block execution of your code. Where your Java-code is located? Disc «C:\» or «F:\»? – Mike Feb 04 '16 at 15:30
  • Which Projekt do you mean? The one I'm working on right now? beacause right now the Batch file is in the folder, where the package, of the class i'm trying to start, is located. Whenever I try to put it somewhere else i cant get the Batch file to start. i guess i'm giving it a wrong comand in that case. Right now it just says: java.exe aufgabenblatt01_Lux_MarieLuise_11099037/AKSTestTask1 and everything is located on F:\ – Ipomea Feb 04 '16 at 15:44
  • Which path to your `BAT` do you use? `F/AKS/Abgaben/Aufgabenblatt1/allesRichtig/runTest1.bat` or `F:\\AKS\\Abgaben\\Aufgabenblatt1\\allesRichtig\\runTest1.bat`? – Mike Feb 04 '16 at 15:49
  • @MaryLu, try edit your `BAT` as it described below: http://stackoverflow.com/questions/12096016/java-cant-find-main-class – Mike Feb 04 '16 at 16:05
  • from what i can see thats pretty much what i wrote :/ java.exe packageName/className and after all it is working when i manually klick it. – Ipomea Feb 04 '16 at 16:15
  • Try to play with `packageName/className` vs. `packageName\\className`. – Mike Feb 04 '16 at 16:23
  • Did all that already. – Ipomea Feb 04 '16 at 16:32