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

时间:2014-01-26 18:09:22

标签: python c bash exec

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

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

1 个答案:

答案 0 :(得分:4)

啊,我想通了。 它应该是:

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

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

相关问题