I have a python script that automates Erdas image processing software based on parameters gathered by the script from the image metadata. The python script gathers these parameters into list which gets written to a batch file, and then runs the batch file, which tells the Erdas software to process the images. When I run this outside of the IIS directory, the script works perfectly. However, when I run the script within the IIS directory, the script partially runs, but gives me an error message when it tries to run the batch file. Just an FYI, I've searched everywhere for a solution to this problem. I've tried changing folder and file permissions and IIS manager settings with no luck. Here is the error message:
Traceback (most recent call last):
File "python_page.py", line 1018, in <module>
main()
File "python_page.py", line 1002, in main
getAtmCorrectBatchFile(AtmCorrectBatchlist)
File "python_page.py", line 912, in getAtmCorrectBatchFile
f = open(basePath + '/atm_batch_process.bat', 'w')
IOError: [Errno 13] Permission denied: 'C:/inetpub/wwwroot/cgi-bin/atm_batch_process.bat'
Below is the code where the error is occurring. What I'm most confused about is that the error is located within the getAtmCorrectBatchFile()
function that creates the batchfile, but the error arises when the script tries to call the RunAtmCorrectBatch()
function listed directly below it. The script has successfully created the batch file and saved it in the cgi-bin directory at this point, so why would the error be within the function that creates the batch file instead of the one that tries to run the batch file?
Edit: I can right click the batch file within the cgi-bin directory and select run, which successfully outputs the processed images, just for some reason this doesn't work when the python script tries to run the batch file.
def getAtmCorrectBatchFile(batchlist):
f = open(basePath + '/atm_batch_process.bat', 'w') #line 912
for i in range (0, len(batchlist)):
f.write(str(batchlist[i]).replace('\\', '/') +'\n')
f.close()
def RunAtmCorrectBatch():
try:
from subprocess import Popen
p = Popen("/atm_batch_process.bat", cwd=basePath)
stdout, stderr = p.communicate()
except WindowsError:
pass