The right way to invoke subprocess.check_output()
or subprocess.Popen()
is passing each term of the command on an element of the list/array, and not creating a long string. You also need to watch the backslashes, they need to be coded:
r = subprocess.check_output(['java', '-Djava.library.path="C:\\Users\\Administrator\\Documents\\NetBeansProjects\\SDK_Java_v1.0.0.2_Beta\\SDK Java_v1.0.0.2 BETA\\Lib"', '-jar', 'C:\\Users\\Administrator\\Documents\\NetBeansProjects\\Busca3-N_java\\dist\\Busca3-N_java.jar', arquivo])
Less importantly, but I also always recommend not writing the path to files or directories explicitly, as this assumes that you are sure which file system is being used (FAT, NTFS, ext3, HFS). It may be that in your case you really make sure that this code will only run on Windows by running NTFS. Anyway, my suggestion is:
import os
home = os.path.expanduser('~')
java_lib = os.path.join(home, 'Documents', 'NetBeansProjects', 'SDK_Java_v1.0.0.2_Beta', 'SDK Java_v1.0.0.2 BETA', 'Lib')
jar_path = os.path.join(home, 'Documents', 'NetBeansProjects', 'Busca3-N_java', 'dist', 'Busca3-N_java.jar')
r = subprocess.check_output(['java', '-Djava.library.path="{}"'.format(java_lib), '-jar', jar_path, arquivo])
The problem is probably in quotes. Try using apostrophes as follows:
subprocess.check_output(['java -Djava.library.path="C:\Users\Administrator\Documents\NetBeansProjects\SDK_Java_v1.0.0.2_Beta\SDK Java_v1.0.0.2 BETA\Lib" -jar C:\Users\Administrator\Documents\NetBeansProjects\Busca3-N_java\dist\Busca3-N_java.jar',arquivo])
– Felipe Avelar