想用c++启动一个python的exe,但该exe依赖一个exe所在路径下的一个文件夹,
现用shellexecute并setcurrentdirectoryA切换路径后发现这个exe还是只能在绝对路径下运行,一旦切换到相对路径D:/ocrdll/,即exe_path(exe所在的文件夹路径)程序直接退出,请问原因是什么,路径不正确吗,应该如何正确设置
bool ocr::data_gen(LPCWSTR exe_path){//LPCSTR exe_path) {
TCHAR chCurDir[MAX_PATH] = { 0 };
GetCurrentDirectory(MAX_PATH, chCurDir);
SetCurrentDirectoryA(exe_path);
//check path;check file name
DWORD dwAttributes = ::GetFileAttributesA(exe_path);
//strcat(StrPath, "\\StorServer.exe");
printf("current working directory: %s\n", _getcwd(NULL, NULL));
if (INVALID_FILE_ATTRIBUTES == dwAttributes)
{
cout << "no file found" << "\n";
return false;
}
ShellExecute(NULL, L"open", L"./data_gen_10.exe", NULL, NULL//此处改exe_path无效, SW_SHOW);
//SetCurrentDirectory(chCurDir);
return true;
}
void main(int argc, char** argv) {
ocr read;
read.train_exe("D:/ocr_dll");
//read.data_gen("D:/ocr_dll");
system("pause");
}