Anand
Anand

Reputation:

Related to executing Java programs through Python

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.

Upvotes: 1

Views: 150

Answers (1)

ironfroggy
ironfroggy

Reputation: 8115

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')])

Upvotes: 2

Related Questions