gpt4 book ai didi

python - 从 C 执行 python 脚本

转载 作者:行者123 更新时间:2023-11-30 15:06:27 25 4
gpt4 key购买 nike

作为我的 C 代码的一部分,我运行 python 脚本,(其中一个 .dll 文件运行该脚本)

getcwd(directory);
ret_value = ShellExecute(NULL,NULL,"myScript.py",NULL,directory,0);

这是程序构建后的文件夹。

如果我从文件夹中运行 .exe,一切都会正常。

错误:如果我在文件夹外搜索程序 .exe 并运行它,则脚本不会运行。

msgVbug.png

搜索:如果我从这里运行它,脚本就不会运行。 Capturesearch.png

最佳答案

GetModuleFileNameW() 函数检索包含指定模块的文件的完全限定路径。这样您就可以找到 .dll 的绝对路径并使用 _chdir 并将当前工作目录更改为该路径。

关于python - 从 C 执行 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38989905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com