I know i am a noop and new in write codes in c++ but, I want to execute cmd lines or a .bat file in c++ code with a return value. i tried it also with follow code:
#include<shellapi.h>
#include <Strsafe.h>
using namespace std;
SHELLEXECUTEINFO ShExecInfo;
CString v_pathToFile_cstr = "...";
CString v_fileName_cstr = "StartServer.bat";
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = v_fileName_cstr;
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = v_pathToFile_cstr;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
//SHELLEXECUTEINFOA(&ShExecInfo);
ShellExecuteEx(&ShExecInfo);
std::cout << "Server Start!\n";
Sleep(1000);
The problem here is that the "StartServer.bat" will be executed but the code is jumping directly to the next line in the code without a return value.
- Is there a way to jump to the next line if the .bat file is finished/closed?
- Is there a way to write the command directly in the cpp file and execute it there without the bat? The bat is only a 4 sentence file?