Hi,

I want to launch a java app from within python, and read back the test the java app writes in a command window. This is using python on windows.

So, I have a basic java app which brings up a cmd.exe widow, and prints "hello world", waits for 5 seconds and then closes the cmd.exe wondow.

I can run os.system("java app etc") and this works fine in that it runs, but I only get a result code sent back to me and not "helloo World"

i.e.

>>>import os
>>>os.system(java stuff)
0
>>>


How do I extract the "hello world" from the cmd.exe window?

Many people who mix java and python use jython (a java based python) instead of python, which allows them to access java classes directly from python. In other versions of python, you must use the subprocess module. I have a code snippet with a Command class here http://www.daniweb.com/code/snippet257449.html You can try

com = Command("java stuff")
com.run()
print com.output
print com.error
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.