Reputation: 4377
I am trying to call a java application from a python script. When Java was installed, a java.exe
program was added to the c:\windows\system32
folder, this folder is included in the PATH
environment variable.
Running
import subprocess
import os
subprocess.call("java") //or "c:/windows/system32/java.exe"
results in
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\Lib\subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "c:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\Lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "c:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\Lib\subprocess.py", line 893, in _execute_child
startupinfo)
WindowsError: [Error 2] Het systeem kan het opgegeven bestand niet vinden
Investigating a bit further, I tried running a console (cmd
) using the same way. When doing a dir c:\windows\system32
in that console, java.exe
is not listed! In fact, a whole bunch of files are not listed compared to running the same command from a "normal" console.
I have no clue what might be causing this, since the exact same workflow does work on another computer. I know I can circumvent the problem by directly calling the java installation, instead of the executable in the system32 folder, but I'd like to find the root of this problem.
This problem is occurring in a Quantum Gis plugin. Quantum Gis uses an included python installation, so I did not install python myself. The python version listed is "2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on Win32". I am running Windows 7 Professional.
Upvotes: 1
Views: 1214
Reputation: 1124858
No, subprocess.call("java")
can never result in a NameError
being thrown.
You are running that without quotes instead:
>>> import subprocess
>>> subprocess.call(java)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'java' is not defined
A NameError
exception is Python telling you the global name java
is not defined in your code, not that the command java
has not been found on your machine.
Upvotes: 4