1

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'

When I try to run the java program from my batch script it runs fine! This is the command I use in my batch script. The issue is with my python code!

java -classpath MqTransfer.jar;com.ibm.mq.commonservices.jar;com.ibm.mq.headers.jar;com.ibm.mq.jar;com.ibm.mq.jmqi.jar;com.ibm.mq.pcf.jar;connector.jar;xerces.jar  com.ibm.my.mq.MyMqTransfer C:\Users\Documents\queueTransfer.properties
3
  • Could you show us the jar META-INF/MANIFEST.MF? Commented Jun 3, 2019 at 20:12
  • I can run the java program perfect from a batch program I use but when I try to invoke from my python program it fails! Commented Jun 3, 2019 at 20:21
  • 1
    Oh it's a Python specific question then. Sorry that I can't help you in there I am a Java dev. Commented Jun 3, 2019 at 20:22

1 Answer 1

2

Based on the error, I believe the process being executed is something like 'java -classpath C:/Users/Documents/MqTransfer.jar c:/Users/Documents/com.ibm.mq.commonServices.jar [followed by the rest of the arguments you are passing to process]' such that java is passed MqTransfer.jar as the entire classpath argument and thinks 'C:.Users.Documents.com.ibm.mq.commonservices.jar' is your class to launch. Try combining your entire intended classpath into the 3rd argument of your launch and I think you will be good. It would look something like this:

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']
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.