19 Sep 2012 05:29 AM |
|
Hi everyone,
I am trying to launch a script written in Python to georeference METEOSAT products from IDL, using the command SPAWN.This code is based on the use of FWTools Shell (windows) and, as far as I understood, IDL opens the cmd shell.Moreover, the python script is located in another folder. I tried manually to open the FWTools Shell, change directory to the location of the script, and launch it (directly calling the python script or calling a .bat file): in this way it works.
With IDL I am not sure how I can set first the FWTools Shell path and then the python script path.I tried something like this:
SETENV, 'VAR=C:\Program Files (x86)\FWTools2.4.7
then I tried to change the directory
cd, 'C:\Program Files (x86)\pythonxy\georeferencer' and launch the script
SPAWN, 'test.bat'
or I set the parameters and sent the command
spawn, ['cmd','params']
It does not work in both the cases.
Any clue?
Thanks in advance
Mitch
|
|
|
|
Deleted User New Member
Posts:  
19 Sep 2012 11:18 AM |
|
Hi Mitch,
To call use SPAWN to call a python script, I used the following procedure:
1) I added the directory with the Python executable into the window search path. To do this you can right click on "My Computer" and select Properties. In the "System Properties" document select the Advanced tab and click on Environment Variables. Edit the environment variable called "Path" and the path to the python executable (in my case it was just "C:\Python27")
2) I then used spawn to call python and had it execute my script by providing the full path to the script. For example:
spawn 'python "C:\Documents and Settings\dstarbuck\My Documents\python_example\write_time_file.py"'
|
|
|
|
Deleted User New Member
Posts:  
20 Sep 2012 01:43 AM |
|
Hey David,
thanks for the help. I think the key is the Environment variable. I set it as PATH in Windows (as you suggested) and in IDL with SETENV. I am actually trying to call a .bat file (it is easy to pass the parameters to the script), moving also the .bat file directly to the path.If I open the FWShell Tools manually and I call the .bat file it works. Through IDL is not working.
SETENV, 'PATH=C:\Program Files (x86)\FWTools2.4.7\'
SPAWN,'C:\Program Files (x86)\FWTools2.4.7\test.bat'
checking the IDL help, I do not understand what happen when I write something like this:
SPAWN, '%PATH%
Is it the way to call a function from the set path?Someone suggested me to use the function "CALL_EXTERNAL", I do not know if it might be better.
|
|
|
|
Deleted User New Member
Posts:  
20 Sep 2012 04:05 AM |
|
I probably got the problem, but not solution..Even if I set the environment variable correctly, SPAWN opens the DOS shell (like from cmd), not the FWTools Shell. Therefore it doesn`t use the proper libraries and the the process crushes.
I do not know if there is a way to open directly the FWTools Shell from IDL...
|
|
|
|
Deleted User New Member
Posts:  
01 Oct 2012 11:59 AM |
|
I don't know much about FWTools Shell but if you can make a resource file ( a file that runs each time the shell opens, ex: .bashrc in a bash shell), perhaps you can use SPAWN to start the FWTools shell and then have your script be called from the resource file.
|
|
|
|