I´m trying to run a python script from R using system()
function:
system('D:/python script.py', wait=T)
The script runs well by itself (double click on it), but when I call it from R it doesn't run and I get the following message:
Warning message:
running command 'D:/python script.py' had status 127
When I try to run it using shell.exec('python script.py')
, it runs perfectly. However, I need to wait the command to finish, to follow to the next line of the code. The argument 'wait' from system()
, system2()
, or shell()
allows me to do that, but shell.exec()
doesn't have a similar argument.
This is the code of my python script applying the Tabulate Area function from ArcGIS:
# Importing libraries
import arcpy
from arcpy import env
from arcpy.sa import *
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Script arguments
Zone_Raster = "D:/Zone_Raster.tif"
Sp_Raster = "D:/Value_Raster.tif"
Tab_Area = "D:/Tab_Area.dbf"
# Tabulate area
TabulateArea(Zone_Raster,"VALUE",Sp_Raster,"VALUE",Tab_Area,"#")
I've also tried calling a .bat file where I pass the arguments to the python script as sys.argv
. The .bat file runs perfectly by itself (double clic on it), but when I call it using system()
or shell()
it doesn't run and returns this message:
'python script.py' is not recognized as an internal or external command,
operable program or batch file
Does any body known how to run the python script or the .bat file using system()
, system2()
, or shell()
? Or how I can make that shell.exec()
waits the command to finish?
Thanks in advance,
Cheers,
Jaime