python - 通过 Exec 在 C 中运行 Python 脚本?

标签 python c bash exec

我想以下列方式在 C 中运行 python 脚本:(我已经 fork 了)

err = execlp("python", "my_script.py", "test", (char*) NULL);

在bash中,我可以成功运行

python my_script.py test

(test 是 python 脚本的参数)

但是,程序输出

my_script.py: can't open file 'test': [Errno 2] No such file or directory

我做错了什么? :3

最佳答案

啊,我想通了。 应该是:

execlp("python", "python", "my_script.py", "test", (char*) NULL);

按照惯例,第一个参数是可执行文件的文件名。我以为这是自动通过的,但显然不是。

关于python - 通过 Exec 在 C 中运行 Python 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21367227/

相关文章:

python 类方法的装饰器

printf_s 和 scanf_s 函数的跨平台使用 - C (linux/win32)

linux - Bash 脚本意外错误 EOF

linux - 是否可以抓取 wget 的最后一行?

linux - 脚本与 ./file_name 一起工作,但是当我使用 sh file_name 启动它时出现错误

python - 在 python 中读取 MySQL blob

python - Red Hat Enterprise Linux Server 版本 6.3 出现 virtualenv AssertionError

python - 如何在 Python 中为多个进程启动和共享一个且唯一的单独进程?

c - 如何按名称(字符串)排序和搜索 BST?

c - 为什么 _mm_permute_ps 的最后一个参数是一个 int?