【发布时间】:2017-10-14 01:48:09
【问题描述】:
我有以下几点:
/* 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 新手,不知道发生了什么。寻求帮助。
先谢谢了!
【问题讨论】:
标签: python c postgresql system-calls