'How to get the PID of the running service in the new window with python?

I want to create a window through CMD / K start, start the jar package in this new window and get the PID of the jar package.I've tried some methods, but none of them can.

pid = Popen(['cmd', '/k', 'start', 'java', '-jar', 'project-0.0.1-SNAPSHOT.jar'], shell=False).pid

pid = Popen(['java', '-jar', 'project-0.0.1-SNAPSHOT.jar', 'cmd', '/k', 'start'], shell=False).pid

Is there any way?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source