Reputation: 1639
I'm trying to execute a java program from a python program :
subprocess.Popen(["java -mx256m -jar /sphinx4-1.0beta5/bin/HelloWorld.jar"], shell=True)
but it fails with this error:
Error: Unable to access jarfile /sphinx4-1.0beta5/bin/HelloWorld.jar
i need to be in an specific directory : /home/karen/sphinx4-1.0beta-src
, to execute the command:"java -mx256m -jar /sphinx4-1.0beta5/bin/HelloWorld.jar"
But i don't know how to do this. I need that my python program execute it !
Upvotes: 4
Views: 864
Reputation: 76
use cwd parameter
subprocess.Popen(["java -mx256m -jar ../sphinx4-1.0beta5/bin/HelloWorld.jar"], cwd=r'path', shell=True)
http://docs.python.org/2/library/subprocess.html "If cwd is not None, the child’s current directory will be changed to cwd before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative to cwd."
Upvotes: 6
Reputation: 189
Your problem is probably related to your path to the jar file. Your code should most likely call /home/Karen/sphynx4-1beta-src in your popen call. This isn't a solution that will work on a different system, unless the file is in the same absolute path though.
Upvotes: 0