【问题标题】:Failed to Execute C function in PostgreSQL that uses system call to run Python script无法在 PostgreSQL 中执行使用系统调用运行 Python 脚本的 C 函数
【发布时间】: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.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 新手,不知道发生了什么。寻求帮助。

先谢谢了!

【问题讨论】:

    标签: python c postgresql system-calls


    【解决方案1】:

    对不起,我太笨了,忘了给example.py添加执行权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      相关资源
      最近更新 更多