Python不调用外部程序 [英] Python not calling external program
问题描述
我编写的python程序有问题。它实际上是plpython3u。我正在从postgres作为触发器运行程序。我很确定触发器部分可以工作。我的测试python程序现在只做2件事。它将一些垃圾写入文件,然后尝试运行C:驱动器(这是Windows系统,BTW)上的程序。我能够写入文件,以便正确调用python程序。作为测试,我尝试运行的程序是一个仅执行COPY的BAT文件。复制从未完成,因此我的调用外部程序的代码无法正常工作。最终,我希望它调用一个真正的Windows应用程序(打开一个窗口。这是执行此操作的最佳方法吗?而且,我通过一个问题此处
I am having problems with a python program that I wrote. It is actually plpython3u. I am running the program as a Trigger from postgres. I am pretty sure the trigger part works. My test python program only does 2 things right now. It writes some junk to a file and then it tries to run a program that is on my C: drive (this is a Windows system, BTW). I am able to write to the file so the python program is being called correctly. As a test the program that I am trying to run is a BAT file that just does a COPY. The copy is never done so my code calling the external program is not working. Ultimately I want this to call a true Windows app (with a window to come up. Is this the best way to do this? Also, I got all the python stuff set up via a question here
我正在将Winows 7计算机与python32一起使用。尽管这可能并不重要,我正在使用postgres 9.2,并且正在通过pgAdmin 1.16中的SQL窗口运行所有这些操作
I am using a Winows 7 machine with python32. Although it probably does not matter, I am using postgres 9.2 and I am running everything all of this via a SQL window from pgAdmin 1.16
这是有问题的代码:
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 os
os.system('"C:\\Users\\Jim\\Desktop\\BATfiles\\run_addcust.bat"')
$$ LANGUAGE plpython3u;
谢谢,
Jim
Thanks, Jim
推荐答案
我更改为子流程,但仍然有问题具有只读权限的Windows 7文件夹。我问了一个问题此处
I changed to the the subprocess but I still have a problem with the Windows 7 Folders having read-only permissions. I asked the question here
这篇关于Python不调用外部程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!