Home > Enterprise >  python How to run a bat file that calls a jarfile [closed]
python How to run a bat file that calls a jarfile [closed]

Time:09-21

I am trying to write a python script that will run a batch file,(i got this part to work). the batch file runs a jar file.

The bat.file by itself runs correctly.

When I run my code it gives me the error

'server.jar' is not recognized as an internal or external command, operable program, or batch file.

Code

import subprocess
subprocess.call([r'C:\Users\starb\Documents\vanila_serv\back.bat'])

CodePudding user response:

try using .getoutput instead of .call

subprocess.getoutput(r'C:\Users\starb\Documents\vanila_serv\back.bat')

CodePudding user response:

The py file was in a different folder from the batch file, so as it was running it was looking for the files the bat file called. As it was in a different folder, it couldn't find the other files it needed in order to run.

By moving the py file into the same directory as the bat file, it was able to find everything it needed to run.

  • Related