Python not calling external program

2024/11/15 21:56:59

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

Answer

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

https://en.xdnf.cn/q/119006.html

Related Q&A

Selenium: How do I retry browser/URL when ValueError(No tables found)

I have a code that scrapes oddsportal website. Sometimes while scraping, I get ValueError("No tables found") and when I manually refresh browser, page loads. How do I do it via code? My code…

For loop for web scraping in python

I have a small project working on web-scraping Google search with a list of keywords. I have built a nested For loop for scraping the search results. The problem is that a for loop for searching keywor…

operation on a variable inside a class in python

Im new with oop and python. Ive been trying to do a simple thing: there is class called Foo(),it contains a variable called x which is initially set to zero.>>>a = Foo() >>>a.x >&g…

Print several sentences with different colors

Im trying to print several sentences with different colors, but it wont work, I only got 2 colors, the normal blue and this redimport sys from colorama import init, AnsiToWin32stream = AnsiToWin32(sys.…

Discord bot to send a random image from the chosen file

I am making a discord bot that randomly chooses an image (images) which is in the same directory (Cats) as the python file(cats.py). This is what my code looks like right now: Cats = os.path.join(os.pa…

pytest - patched method of a class does not return the mock value

My code is fairly simple but i dont understand what is going on :class MyDb :def some_func( arg ) :....while my test code is :@mock.patch(mypkg.mydb) @pytest.mark.parametrize( func_dummy_value ) :( [ {…

New instance of toplevel classes make overlapping widgets

Im generally new to python and tkinter. Ive been programming maybe about a year or so, and Ive just started to try to make each tkinter toplevel window its own class because Ive heard that its the righ…

Regex End of Line and Specific Chracters

So Im writing a Python program that reads lines of serial data, and compares them to a dictionary of line codes to figure out which specific lines are being transmitted. I am attempting to use a Regul…

Is it possible to scrape webpage without using third-party libraries in python?

I am trying to understand how beautiful soup works in python. I used beautiful soup,lxml in my past but now trying to implement one script which can read data from given webpage without any third-party…

Different model performance evaluations by statsmodels and scikit-learn

I am trying to fit a multivariable linear regression on a dataset to find out how well the model explains the data. My predictors have 120 dimensions and I have 177 samples:X.shape=(177,120), y.shape=(…