How to invoke a java program with classpath from Python 3.x

Keywords: java python-3.x executable-jar

Question: 

I am trying to execute an external java program from a python 3.7 program using the java command with classpath. I am using subprocess.Popen module in Python. Somehow I am not able to get it working! Appreciate any assistance!

cmd = ['java',
           '-classpath', 'C:/Users/Documents/MqTransfer.jar', 'C:/Users/Documents/com.ibm.mq.commonservices.jar',
           'C:/Users/Documents/com.ibm.mq.headers.jar', 'C:/Users/Documents/com.ibm.mq.jar',
           'C:/Users/Documents/com.ibm.mq.jmqi.jar', 'C:/Users/Documents/com.ibm.mq.pcf.jar',
           'C:/Users/Documents/connector.jar', 'C:/Users/Documents/xerces.jar',
           'MyMqTransfer', 'C:/Users/Documents/queueTransfer.properties']
    jproc = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE)
    output, errors = jproc.communicate()
    print(output, errors)

I am getting the below error

b'' b'Error: Could not find or load main class C:.Users.Documents.com.ibm.mq.commonservices.jar\r\n'

Answers: