最开始的方案是使用 system 指令来运行python程序,但是始终有一个黑色窗口无法去除,即便使用了 pyw pythonw.exe 还是存在这个问题,后来发现需要使用另外一个指令即可。
#include <stdio.h>
#include <stdlib.h>
int main()
{
system("python.exe xxx.py");
return 0;
}
修正后的方案;
#include <windows.h>
#include <Shellapi.h>
int main()
{
ShellExecuteA(NULL, "open", "pythonw.exe", "xxxx.py", NULL, SW_HIDE);
return 0;
}