-1

This is for a minecraft server, I'm using python to handle multiple server folders each one has a start.bat in it.

This is what the start.bat looks like:

java -Xmx4G -jar server.jar nogui
pause

It works fine if I double-click it, however, if I call it from python like this:

import os
os.system('server\\start.bat')

Python says: '1' and cmd says: Error: Unable to access jarfile server1.15.jar

I looked at this post, and tried the following:

  • changed 'server.jar' to 'server' in the start.bat
  • changed directory
  • provided a full path to the start.bat file
  • checked for spaces in my path (and found none)
  • tried running the file as administrator

None of the above worked for me, any clue?

edit 2: I could also start the jar file directly from python, without using the bat file, but I hava no idea how to do it

NotLatif
  • 1
  • 3
  • Does this answer your question? [What causes "Unable to access jarfile" error?](https://stackoverflow.com/questions/11943948/what-causes-unable-to-access-jarfile-error) – mojozinc May 27 '20 at 12:32
  • https://stackoverflow.com/questions/11943948/what-causes-unable-to-access-jarfile-error this might help – mojozinc May 27 '20 at 12:33
  • If you're running it from `system`, does that have the required permissions for the `.jar` file? – Compo May 27 '20 at 12:38
  • Have you tried providing a fully qualified path to `start.bat`? C:\path\to\server\start.bat – lit May 27 '20 at 13:09
  • I edited the post, also, how do I know if `sysyem` has the required permissions? – NotLatif May 27 '20 at 16:06
  • I'm using python to manage my server folder (which contains lots of servers), I can bypass the batch script, that's not really a problem, however I am building a python script so I can manage all the `server.properties` files to sync with ip, port etc. and for other functions like stopping, restarting the server, making a backup, and other things. I know, there are a lot of tools that already do that, but It is fun to build things on my own and learn that way – NotLatif May 28 '20 at 09:21

1 Answers1

0

Resolved:

Maybe this is obvious for a lot of people but I'll write what worked for me to help people with the same issue.

Let's say whe have this folder structure:

folder\start.py #is the python starter
folder\server\server.jar #is the server jar
folder\server\start.bat #is the server jar starter (java -Xmx1500M -Xms125M -jar server.jar nogui)

When with python you call os.system('server\\start.bat') it opens a new console which led me thinking it was the start.bat cmd, it is not, in fact python executing your batch commands in the folder directory.

There are two methods I found to resolve this issue and both of them are not really convinient (I guess I'll make a python function to automate the process):

Option one: change the start.bat file to java -Xmx1500M -Xms125M -jar server\server.jar nogui

Option two: change the start.bat adding cd server before the first line.

NotLatif
  • 1
  • 3