Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

postgresql - Python not calling external program

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

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

Here is the code with the problem:

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;

Thanks, Jim

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...