简体   繁体   English

从C执行python脚本

[英]Execute python script from C

As part of my C code I run python script,(one of the .dll files runs the script) 作为我的C代码的一部分,我运行python脚本,(。dll文件之一运行脚本)

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

This is the folder of the program after build. 这是构建后程序的文件夹。

If I run the .exe from the folder every thing works. 如果我从该文件夹中运行.exe,则一切正常。

The bug: If I search program .exe outside the folder and run it the script doesn't run. 错误:如果我在文件夹外搜索程序.exe并运行该脚本,则脚本不会运行。

msgVbug.png

Search: If I run it from here the script doesn't run. 搜索:如果我从此处运行该脚本,则该脚本不会运行。 Capturesearch.png

GetModuleFileNameW() function retrieves the fully qualified path for the file that contains the specified module. GetModuleFileNameW()函数检索包含指定模块的文件的标准路径。 This way you can find absolute path of the .dll and use _chdir and change the current working directory to that path. 这样,您可以找到.dll的绝对路径并使用_chdir并将当前工作目录更改为该路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM