Unable to access jarfile - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Unable to access jarfile (/thread-34390.html) |
Unable to access jarfile - Rakshan - Jul-27-2021 I had a java application which was testing servers. We are migrating to python, and for a start we are making use of the jar from the java application. I use the jar in my python script, and call the subprocess.call( ['java', '-jar', 'XYZ.jar', '-url', 'opc.tcp://localhost:XXXX', '-check', 'AB', '-specVersion', '2.0', '-test', 'testclient.TestGeneral'])This works perfect! However, we plan to have a clear structure by using classes(OOP). So I make some modifications and I write the below `class TestClient: def performTest(self): subprocess.call(['java', '-jar', 'XYZ.jar', '-url', 'opc.tcp://localhost:XXXX', '-check', 'AB', '-specVersion', '2.0', '-test', 'testclient.TestGeneral']) if __name__ == "__main__": client = TestClient() client.performTest() `I get an error saying `
`How is it that the jar becomes unaccesable? Am i missing something here? Please let me know RE: Unable to access jarfile - DeaD_EyE - Jul-27-2021 I guess you're running your tool in a different directory and Python is searing at the wrong places. import subprocess from pathlib import Path script_dir = Path(__file__).parent jar_file = script_dir / "XYZ.jar" subprocess.call(["echo", "Path", jar_file.absolute()]) Quote:Changed in version 3.6: args parameter accepts a path-like object if shell is False and a sequence containing path-like objects on POSIX. If your Program have to be stated inside the program directory, you can tell this subprocess to do. # will print /var subprocess.call(["pwd"], cwd="/var") RE: Unable to access jarfile - Rakshan - Jul-28-2021 Thank you for the suggestion. I got it working, as I had not added the direectory path in pycharm. |