I use CreateProcess () to run an external console application on Windows from my GUI application. I would like to somehow collect the conclusion to find out if there were any errors. Now I know that I need to do something with hStdOutput, but I do not understand what. I am new to C ++ and an inexperienced programmer, and in fact I do not know what to do with a pen or how to light a pipe.
How to get the output of a variable (or file)?
Here is what I have a moment:
void email::run(string path,string cmd){ WCHAR * ppath=new(nothrow) WCHAR[path.length()*2]; memset(ppath,' ',path.length()*2); WCHAR * pcmd= new(nothrow) WCHAR[cmd.length()*2]; memset(pcmd,' ',cmd.length()*2); string tempstr; ToWCHAR(path,ppath); //creates WCHAR from my std::string ToWCHAR(cmd,pcmd); STARTUPINFO info={sizeof(info)}; info.dwFlags = STARTF_USESHOWWINDOW; //hide process PROCESS_INFORMATION processInfo; if (CreateProcess(ppath,pcmd, NULL, NULL, FALSE, 0, NULL, NULL, &info, &processInfo)) { ::WaitForSingleObject(processInfo.hProcess, INFINITE); CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); } delete[](ppath); delete[](pcmd); }
This code probably makes any decent programmer scream, but (I shouldn't even say that :) This works; -)
Question: How to use hStdOutput to read output to a file (for example)?
c ++ createprocess
Stef
source share