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

前端 未结 2 573
抹茶落季
抹茶落季 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:19

    In general: Use os.chdir to change the directory of the parent process, then os.system to run the jar file. If you need to keep Python's working directory stable, you need to chdir back to original working directory - you need to record that with os.getcwd().

    On Unix: Create a child process with os.fork explicitly. In the parent, wait for the child with os.waitpid. In the child, use os.chdir, then os.exec to run java.

提交回复
热议问题