1
我有以下幾點:無法執行在PostgreSQL的C函數使用系統調用來運行Python腳本
/* execute_py.c */
#include <stdio.h>
#include <stdlib.h>
#include "postgres.h"
#include "fmgr.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
int
call_py()
{
printf("Executing your Python script...");
return system("python36 absolute/path/to/example.py");
}
和:
# example.py
with open("absolute/path/to/test.txt", "w") as f:
f.write("hello world")
我編譯C腳本爲execute_py.o
和execute_py.so
然後創建PostgreSQL服務器中的一個函數:
CREATE OR REPLACE FUNCTION call_py() RETURNS integer
AS 'absolute/path/to/execute_py', 'call_py'
LANGUAGE C STRICT;
並試圖運行像這樣的功能:
SELECT call_py();
該函數返回0。但是,當我檢查了文件夾,裏面就是沒有生成test.txt
。
我是新的C和不知道發生了什麼事。尋求幫助。
謝謝!