Python不调用外部程序第2部分 [英] Python not calling an external program part 2

查看:79
本文介绍了Python不调用外部程序第2部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行python程序(plpython3u,实际上)作为来自postgres(9.2)的触发器时遇到问题。触发器使用以下语句调用python程序:
perform scalesmyone(new.id);

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);

python程序成功将某些内容写入文件(这表明对我来说,触发器正在起作用),然后尝试在Windows 7计算机上的C:驱动器上运行程序。它因以下错误而失败:错误:WindowsError:[错误5]访问被拒绝。我现在正在使用子流程调用,但是以前我尝试了子流程调用,但是没有用。您可以看到此处

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

这是代码:

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;

文件在那里。

吉姆

推荐答案

错误提示用户运行Postgres / plpython没有对该.bat文件的执行权限(至少那是我在普通Python程序中获得的权限)。这可能不是子流程本身的问题。

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.

这篇关于Python不调用外部程序第2部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆