2017-10-14 137 views
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.oexecute_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和不知道发生了什么事。寻求帮助。

谢谢!

回答

1

对不起,我太傻了,忘了执行权限添加到example.py

相关问题