How can I get my python (version 2.5) script to run a jar file inside a folder instead of from command line?

前端 未结 2 567
抹茶落季
抹茶落季 2020-12-18 12:52

I am familiar with using the os.system to run from the command line. However, I would like to be able to run a jar file from inside of a specific folder, eg. my \'t

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 13:25

    Here is a small script to get you started. There are ways to make it "better", but not knowing the full scope of what you are trying to accomplish this should be sufficient.

    import os
    
    if __name__ == "__main__":
       startingDir = os.getcwd() # save our current directory
       testDir = "\\test" # note that \ is windows specific, and we have to escape it
       os.chdir(testDir) # change to our test directory
       os.system("java -jar run_this.jar required_paramter.ext")
       os.chdir(startingDir) # change back to where we started
    

提交回复
热议问题