I am having problems running a python program (plpython3u, really) as a trigger from postgres (9.2). The trigger calls the python program with the following statement:
perform scalesmyone(new.id);
The python program writes something to a file successfully (which indicates to me that the trigger is working) and then tries to run a program on the C: drive on my Windows 7 machine. It fails on that with this error: ERROR: WindowsError: [Error 5] Access is denied. I am using a subprocess call now but previously I tried a subprocess call but that did not work. You can see that here
Here is the code:
CREATE or replace FUNCTION scalesmyone (thename text)
RETURNS int
AS $$
a=5
f = open('C:\\JUNK\\frompython.txt','w')
f.write(thename)
f.close()
import subprocess
return_code = subprocess.call(["C:\\Users\\Jim\\Desktop\\BATfiles\\run_addcust.bat", '"hello"'])
$$ LANGUAGE plpython3u;
The file is there.
Jim
The error suggests user that runs Postgres/plpython has no execution permissions on that .bat file (at least that’s what I was getting in plain Python programs). This might not be a problem with subprocess itself.