1

I am using os.system to execute a java program through a python script. I need to pass a file name to the java program as an argument. I am not able to figure out how to pass the relative file location. What should be my reference for determining the relative location. I tried to use the location of the python script as the reference but doesn't work.

1 Answer 1

2

See the subprocess module for all your external process invoking needs.

p = subprocess.Popen(['myjavaapp', 'afilename.txt'])

If you need to get the relative location and you aren't sure how the other command is going to take it, make it absolute.

p = subprocess.Popen(['myjavaapp', os.path.abspath('afilename.txt')])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.